April 11, 2014 at 12:16 am
Hugo Kornelis (4/10/2014)
Just for the record - GO is not a statement, it is a batch separator. It will be intercepted and handled by the client. Send a "GO" to SQL Server, and you'll get an error.Proof:
EXEC ('GO');
+1
April 12, 2014 at 3:05 am
I know this CHAR(13) + CHAR(10) method based on a painful previous experience 🙂
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
April 12, 2014 at 10:39 am
SQLRNNR (4/9/2014)
sestell1 (4/9/2014)
timwell (4/9/2014)
For both versions I got this:Msg 102, Level 15, State 1, Line 26
Incorrect syntax near 'GO'.
"None of the above" was not an option so I knew something was off...
Did anyone else get that? I am using 2008 R2 (and changed the names to tables and fields in my test data.)
Same here. The SSMS results window seems to convert both CR and LF to a space.
For it to work properly you need to choose to have the results go to text rather than grid in SSMS. Then there is only one correct answer.
Interetsing theory. Never in all the years I have used SQL Server has sending results to grid (whether in Query Analyser or in SSMS) removed LF characters; and never has copy and paste in any variant of windows from win 2000 to win 8.1 (I've used both those and everything in between) dropped the LF characters that QA or SSMS put into the grid. So something must differ between my system and yours - I was surprised enough when I saw your post to go an check on my system.
Tom
April 17, 2014 at 12:24 pm
Cool question. Thanks.
- webrunner
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
April 20, 2014 at 1:02 pm
Yes.I too got the same result.
April 23, 2014 at 8:07 am
That explains why last statement below won't work:
declare @dsql nvarchar(512) = ( SELECT TOP 1 'DELETE FROM [AdventureWorks2012].[Person].[BusinessEntityAddress] ' + CHAR(13) + 'WHERE [BusinessEntityID]='+CAST([BusinessEntityID] AS VARCHAR(50))+ CHAR(13) + CHAR(10) + 'GO 3'
FROM [AdventureWorks2012].[Person].[BusinessEntityAddress] )
print @dsql
execute(@dSQL)
January 26, 2015 at 5:33 pm
+1
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply