Last post Oct 18, 2020 08:38 AM by PatriceSc
Oct 18, 2020 06:37 AM|robby32|LINK
I am trying to create a stored procedure in sql from c#. I run the following:
IF EXISTS ( SELECT type_desc, type FROM sys.procedures WITH(NOLOCK) WHERE name = 'proc5' AND type = 'P' ) DROP PROCEDURE dbo.proc5 GO CREATE PROC dbo.proc5 AS begin select * from [Details] end
But I get the error:
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
I need to check if it exists first ?
How can i run the statement to create a Stored Procedure from c#
Oct 18, 2020 08:38 AM|PatriceSc|LINK
I've seen once that GO is processed by client side tools rather than on the server side. So you'll likely have to send each statement separately.
If using SQL Server 2016 or later you can use "CREATE OR ALTER PROC dbo.proc5 AS begin select * from [Details] end" to either create or alter a stored proc.