Hi James,
Why not drop the proc if it exists and then the create can happen in its own batch regardless (I've changed the SP so I didn't need your tables on my box to test):
IF exists(select * from sysobjects where id = object_id('prGetEqId') and OBJECTPROPERTY(id,'IsProcedure')=1)
drop Procedure prGetEqId
go
Create Procedure prGetEqId
@Make varchar(50),
@Model varchar(50)
as
SELECT @make as Make, @Model as Model
I guess this might still barf if there is a dependency on the SP somewhere ...
Cheers,
Andrew
>I am trying to check for the existance of a procedure and if it exists I want to alter it. If not I want to create it. When I place this code in the Query Analyzer of MSFT I get an error saying there is a problem near Procedure in line 2. Does anyone know why?
>
>If I delete all lines except for the IF and add in a DROP PROCEDURE prGetEqId it works. If I just put in the Alter Procedure it works.
>
>If I put in a BEGIN/END after the IF I get an error.
>
>
>Thanks for any assistance in advance.
>
>Jim
>
>HERE IS THE CODE:
>
>IF exists(select * from sysobjects where id = object_id('prGetEqId') and OBJECTPROPERTY(id,'IsProcedure')=1)
>Alter Procedure prGetEqId
> @Make varchar(50),
> @Model varchar(50)
> as
> SELECT EquipmentId
> FROM Equipment
> WHERE Make = @Make
> and Model = @Model
>ELSE
> Create Procedure prGetEqId
> @Make varchar(50),
> @Model varchar(50)
> as
> SELECT EquipmentId
> FROM Equipment
> WHERE Make = @Make
> and Model = @Model
If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?
From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."
All my FoxTalk and other articles are available on my
web site.
Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.