Home Dashboard Directory Help

SQL Server 2012 sqlcmd: Unexplained behaviour returning output containing square brackets [] by swh1



Sign in
to vote
Type: Bug
ID: 812101
Opened: 12/20/2013 6:40:51 AM
Access Restriction: Public
User(s) can reproduce this bug


From a SQL Server 2012 installation (SQL Server 2012 patched to sp1 (11.0.3000.0); and sqlcmd reporting: Version 11.0.2100.60 NT x64), executing either:

sqlcmd /E -S <ServerName> -Q "PRINT '[A], [B], [C]'" or

sqlcmd /E -S <ServerName> -Q "PRINT CHAR(91) + 'A], [B], [C]'"


, [B], [C]

wheras for 2005, 2008 or 2008R2, gives the expected result of:-

[A], [B], [C]

I haven't been able to find an explanation or way to force the correct result from 2012 sqlcmd. It appears to me that 2012 is interpreting a lefthand square bracket as the first character on a line as some sort of token delimiter or similar.

Can anyone shed some light on this? This is just an example of the problem, I am not actually trying to print [A], [B], [C]! :) - we are experiencing data loss/corruption on outputs from stored procedures where the leftmost character is [.

Note that 2012 sqlcmd expects a closing ] on the line, otherwise the output gets returned like this for:-

sqlcmd /E -S <ServerName> -Q "PRINT '[A, [B], [C'"

[Microsoft][SQL Server Native Client 11.0][SQL Server][A, [B], [C


(Virtualization: VMWare)
Sign in to post a comment.
Posted by swh1 on 2/28/2014 at 12:35 AM
Seems like this feedback has fallen on deaf ears!!
Posted by swh1 on 12/23/2013 at 1:40 AM
The workaround posted by Balmukund is not strictly a workaround. To achieve this (adding a leading space), we would need to check and edit hundreds of stored procedures, and there will be secondary affects by adding characters to the output.
Sign in to post a workaround.
Posted by Balmukund on 12/21/2013 at 4:02 AM
So, its not a [A] which is a problem its "[" as the first character of the output.

I agree that it's an issue with SQLCMD in SQL 2012. If you capture profiler, command is passed correctly to SQL engine. It seems like when output stream comes out, SQLCMD looks for "[" as first character and chops off content till next "]"

If there is not matching closing "]" it shows the text with additional message.

Workaround - Just add additional space prior to square bracket and it works fine.