Home > Net >  Ignoring Scripting variables in sqlcmd (Importing database)
Ignoring Scripting variables in sqlcmd (Importing database)

Time:01-24

I am having a database import being done form a SQL file and i see my content have some data that is conflicting with sqlcmd import. The following queries are the 2 scenarios i am encountering in my import.

INSERT INTO [users] ([id],[email],[title],[desc]) VALUES (1096,'[email protected]',N'Shami Doc', N'This is profile of Shami who sends $(mid) message');

In this query am getting the following error...

'mid' scripting variable not defined.

Now in the second case...

INSERT INTO [users] ([id],[email],[title],[desc]) VALUES (1091,'[email protected]',N'Raj Doc', N'This is profile of Raj who sends $(m message');

Am getting Syntax Error. In actual i just want both data to be imported to users table with the same data defined... i mean the $(mid) should be imported just as text into that column and also $(m should be imported as same.

I tried using escape character backslash and it did not help. Can someone help me in this ? How can i have both above queries run without loosing that data ?

CodePudding user response:

Specify the -x SQLCMD command-line option to ignore scripting variables when executing scripts where scripting variables need to be retained as data. For example:

SQLCMD -S YourServer -x -E -I -i YourScript.sql
  • Related