在新的(对我来说)环境中使用sqlcmd会产生一些奇怪的结果。使用print语句时,第一个字符是方括号(即[])它不会打印。我的测试如下。
print "statement bug - square bracket as first character - bit printed but [test] missing" -- :r "test.print.sql" :out "test.print.txt" print "first character is [ with matching ]"; print "[test]bit" print "[test]bit"; print '[test]bit' print '[test]bit'; print "first character is [ without matching ]"; print "[test bit" print "[test bit"; print '[test bit' print '[test bit'; print "first character is [ without matching ] no text"; print "[" print "["; print '[' print '['; print "first character is space = all ok"; print " [test]bit" print " [test]bit"; print ' [test]bit' print ' [test]bit'; print "last character is space "; print "[test]bit " print "[test]bit "; print '[test]bit ' print '[test]bit '; print "()"; print "(test)bit " print "(test)bit "; print '(test)bit ' print '(test)bit '; print "{}"; print "{test}bit " print "{test}bit "; print '{test}bit ' print '{test}bit '; go :out stdout
输出如下:
statement bug - square bracket as first character - bit printed but [test] missing
first character is [ with matching ]
bit
bit
bit
bit
first character is [ without matching ]
[Microsoft][SQL Server Native Client 11.0][SQL Server][test bit
[Microsoft][SQL Server Native Client 11.0][SQL Server][test bit
[Microsoft][SQL Server Native Client 11.0][SQL Server][test bit
[Microsoft][SQL Server Native Client 11.0][SQL Server][test bit
first character is [ without matching ] no text
[Microsoft][SQL Server Native Client 11.0][SQL Server][
[Microsoft][SQL Server Native Client 11.0][SQL Server][
[Microsoft][SQL Server Native Client 11.0][SQL Server][
[Microsoft][SQL Server Native Client 11.0][SQL Server][
first character is space = all ok
[test]bit
[test]bit
[test]bit
[test]bit
last character is space
bit
bit
bit
bit
()
(test)bit
(test)bit
(test)bit
(test)bit
{}
{test}bit
{test}bit
{test}bit
{test}bit
2008R2和2012(SP1)下的结果相同。并且直接触发命令而不使用:run /:out to file wrapper。