Dollar Sign at the end of table name causes problem in SQL CMD

Professionaluser
Posted by Professionaluser under Sql Server category on | Points: 40 | Views : 414
If you run the below code in SSMS, it works fine and returns correct output; where as SQLCMD returns ERROR
CREATE TABLE #Tab$ (c1 int)
INSERT #Tab$ (c1) VALUES (1)
SELECT * FROM #Tab$
DROP TABLE #Tab$
GO

save above code in the path C:\Temp\TestDollarSymbol.sql; gives us error if you run same code through SQLCMD
C:\Temp>sqlcmd -SServerName  -dtempdb  -iC:\Temp\TestDollarSymbol.sql

Sqlcmd: Error: Syntax error at line 1 in file 'C:\Temp\TestDollarSymbol.sql'.

REMEDY: remove $ at the end of table name and save file to run the below part

CREATE TABLE #Tab(c1 int)
INSERT #Tab(c1) VALUES (1)
SELECT * FROM #Tab
DROP TABLE #Tab
GO


--run below query in SQL CMD, it returns NO ERROR
C:\Temp>sqlcmd -SServerName  -dtempdb  -iC:\Temp\TestDollarSymbol.sql 


Output in SQL CMD
(1 rows affected)
c1
-----------
1

(1 rows affected)

Comments or Responses

Login to post response