Question: If I add IF not exists to a create procedure as external name statement, I get a syntax error… why?
Both statements work fine if I run them separately…
IF NOT EXISTS
(
SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'PriceSum')
AND type in (N'P', N'PC')
)
CREATE PROCEDURE PriceSum(@sum int OUTPUT)
AS EXTERNAL NAME MyFirstUdp.[SQL_CLRdll.MySQLclass].PriceSum
because the CREATE PROCEDURE has to be the first statement in a batch.
either drop the proc first or use dynamic SQL
you can also reverse the logic