January 26, 2008 at 1:06 pm
When executing the query which is stored in a variable like that :
exec (@test_SQL)
This is alright for simple query, but this method is not work for a query with “go”. Syntax error will come out.
declare @test_SQL varchar (max)
set @test_SQL = 'print(''aaa'') ' + char(10)+ 'go print(''bbb'')'
print @test_SQL
exec (@test_SQL)
Any idea to deal with this?
Thanks in advance.
January 26, 2008 at 6:07 pm
"GO" isn't actually a part of T-SQL and it can't be used the way you want in Dynamic SQL...
--Jeff Moden
January 27, 2008 at 10:57 pm
GO is a transaction seperator, but it is a query window (and osql/sqlcmd) specific code.
January 28, 2008 at 1:05 am
What are you trying to accomplish? Why does it need the GO statement separator?
If you need the GO statement separator then you could do two exec calls rather than one. However, I'd wager that you don't need it - try to remove the GO and see if it goes. 😀
January 28, 2008 at 6:28 am
o... thanks a lot !!!
exec 2 query separately is a good idea, thanks to knock me up !!!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply