microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
337 stars 59 forks source link

go-sqlcmd is failed to execute the tsql script contains any special charectors #239

Closed prmadhes-msft closed 1 year ago

prmadhes-msft commented 1 year ago

Below command is executing fine in SSMS but failed when executing like sqlcmd -Sgo-sqlcmdvm -iF:\specialchar_sql.sql --Create TestDB USE TestDB; GO

CREATE TABLE temptable( ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED , Item VARCHAR(50), value VARCHAR(50), ); INSERT INTO dbo.temptable ( Item, value ) VALUES ( 'Item-A', '$(100.12)' ); GO

Error details

C:\Users\sqladmin>sqlcmd -Sgo-sqlcmdvm -iF:\specialchar_sql.sql Changed database context to 'TestDB'. Sqlcmd: Error: Syntax error at line 10

image

shueybubbles commented 1 year ago

using $() syntax doesn't work in sqlcmd because it's interpreted as a variable referenece. Disable variable evaluation.