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_GetApprovalQ uestions' AND type = 'P')
DROP PROCEDURE QT_Checklist_GetApprovalQu estions
GO
CREATE PROCEDURE [dbo].[QT_Checklist_GetApp rovalQuest ions] AS
Select * From QT_Sites_ApprovedVolumes_Q uestions
GO
end
--- gives error - "Incorrect syntax near GO"
declare @isCorpDB as bit
set @isCorpDB = 0
if (@isCorpDB=1)
begin
IF EXISTS(SELECT name FROM sysobjects WHERE name = 'QT_Checklist_GetApprovalQ
DROP PROCEDURE QT_Checklist_GetApprovalQu
GO
CREATE PROCEDURE [dbo].[QT_Checklist_GetApp
Select * From QT_Sites_ApprovedVolumes_Q
GO
end
--- gives error - "Incorrect syntax near GO"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I guess that's all I'm going to get on this, thanks aneeshattingal
ASKER