Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using double quotes in a T-SQL script fails in SQLCMD, but not SSMO

Executing the following script via sqlcmd fails. However, executing it via ssmo or SQL Server Management Studio works.

sqlcmd -S . -d test -i input.sql

input.sql:

CREATE FUNCTION test()  
RETURNS  @t TABLE ("ID" INT)  
AS  
BEGIN  
 RETURN  
END  

Even when I put SQL Server Management Studio into sqlcmd mode, it still fails. This is a problem as we test our scripts with SSMS, but deploy with SQLCMD. Thus we only find out our code doesn't work when we attempt to deploy.

Why does sqlcmd behave like this? Is there any way to turn it off?

like image 766
RichB Avatar asked Oct 29 '10 16:10

RichB


1 Answers

If you really need to use double quotes to delimit identifiers in your scripts, you'd need to set the quoted_identifier option on SQLCMD by using the -Ienable switch. It is OFF by default in SQLCMD but ON by default in SSMS, which is why your tests work in SSMS.

Read more about QUOTED_IDENTIFIER here.

like image 120
Joe Stefanelli Avatar answered Sep 24 '22 14:09

Joe Stefanelli