Link to home
Start Free TrialLog in
Avatar of bmutch
bmutch

asked on

create sql server script that optionally creates stored procs based on value of a variable

I need to run a script 2 times, once for a local DB and once for a "server" DB, that will perform certain operations on both DB's, but only on the local DB for other opeartions. I would like to set a variable at the top then run script, reset it, then run script again, but my "if" statements are invalid syntax because the create SP statemtent is not playing well with the begin/end and the if statements:

declare @isCorpDB as bit
set @isCorpDB = 0


if (@isCorpDB=1)
begin
IF EXISTS(SELECT name FROM sysobjects WHERE name = 'QT_Checklist_GetApprovalQuestions' AND type = 'P')
   DROP PROCEDURE QT_Checklist_GetApprovalQuestions
GO  
CREATE PROCEDURE [dbo].[QT_Checklist_GetApprovalQuestions] AS
Select * From QT_Sites_ApprovedVolumes_Questions
GO

end


--- gives error - "Incorrect syntax near GO"
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bmutch
bmutch

ASKER

a pain either way, dynamic sql or 2 scripts with a lot of duplication, thanks again M$.
Avatar of bmutch

ASKER

I guess that's all I'm going to get on this, thanks aneeshattingal