December 4, 2014 at 1:25 pm
Hi all,
I am attempting to create a simple script that will create different stored procedures in different environments (DEV,TEST, PROD) based on the server name as in below. This is how they want the code deployed (in one script). The reason: The tables that they derive from have differing field names per environment.
IF @@SERVERNAME = 'xyz'
BEGIN
CREATE PROC dbo.AAA
AS
SELECT TOP 10 * FROM Sometable
END
IF @@SERVERNAME = 'cde'
BEGIN
CREATE PROC dbo.AAA
AS
SELECT TOP 10 * FROM Sometable
END
getting "Incorrect syntax near the keyword 'PROC'." I guess you can't do this?
Thanks in advance.
December 4, 2014 at 2:00 pm
since CREATE PROC/VIEW/FUNCTION/TRIGGER has to be the first statemtn in the batch, you have to go with dynamic SQL
IF @@SERVERNAME = 'xyz'
BEGIN
EXEC('CREATE PROC dbo.AAA
AS
SELECT TOP 10 *
FROM Sometable');
END
IF @@SERVERNAME = 'cde'
BEGIN
EXEC('CREATE PROC dbo.AAA
AS
SELECT TOP 10 *
FROM Sometable');
END
Lowell
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply