Solved

Statement separators in Dynamic SQL in SQL Server

Posted on 2008-10-02
6
499 Views
Last Modified: 2012-08-14
Hello,
I have a situation where I need to issue a statement separator (like go) in dynamic sql.

Example:
Declare @sql varchar(1000)
select @sql = "Drop Proc testproc go Create Proc testproc"
Execute (@sql)

Please let me know how to do this in SQL Server (2000/2005).

Thanks,
Harish
0
Comment
Question by:Harish Varghese
  • 3
  • 3
6 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22626443
does your statement not execute?
0
 
LVL 12

Author Comment

by:Harish Varghese
ID: 22626776
Hi chapmandew,
I get below error when I execute the above example:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'go'.
Server: Msg 111, Level 15, State 1, Line 1
'CREATE PROCEDURE' must be the first statement in a query batch.
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22626798
yep.  Looks like you can't do it....you're going to need to split it into 2 different statements.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 12

Author Comment

by:Harish Varghese
ID: 22626878
Ok.
I believe statement separators are handled by the query tool (Query Analyzer, SQL Server Management Studio etc).
I executed the below batch in Query Analyzer.
Drop Proc testproc
go
Create Proc testproc as select 1

I saw two batches 'Drop Proc testproc' and 'Create Proc testproc as select 1' in Profiler.
So, I believe, it may not be possible execute two sql batches together.
Thanks,
Harish
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22626883
you are correct, sir.
0
 
LVL 12

Author Closing Comment

by:Harish Varghese
ID: 31502468
Hi,
Though I did not get a solution for my problem, I am giving you points because I think there is no solution to this.
Thanks,
Harish
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why does this keep coming up NULL? 2 43
How to run sql statements from SQLCMD or command line 2 55
sql Audit table 3 59
Grid querry results 41 72
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now