Hi Folks,
I've been working with SQLCMD mode again today and one thing about it always bites me. If I execute a script like:
:CONNECT SERVER1
SELECT @@VERSION;
:CONNECT SERVER2
SELECT @@VERSION;
:CONNECT SERVER3
SELECT @@VERSION;
I'm sure I'm not the only person that would be surprised to see all three SELECT commands executed against SERVER3 and none executed against SERVER1 or SERVER2. If you think that's odd behavior, here's where to vote: https://connect.microsoft.com/SQLServer/feedback/details/611144/sqlcmd-connect-to-a-different-server-should-be-an-implicit-batch-separator#details
Try this :
:CONNECT SERVER1
SELECT @@VERSION;
go
:CONNECT SERVER2
SELECT @@VERSION;
go
:CONNECT SERVER3
SELECT @@VERSION;
go
Hi Duray,
I know how to fix it but the issue is whether or not the current behavior is sensible. I don't think it is.
Regards,
Greg
I ran into this issue today. Very frustrating!
While parsing and executing are two different things, in SQLCMD mode they both mean the same thing-EXECUTE
BOL does not say much about SQLCMD mode. One need to experiment and verify. It is reasonable to use the batch separator.
The outcome (as it presently works) is both bizarre and unexpected. I think it should be changed.