0

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 ?

1 Answer 1

1

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

Note this example also includes the -I option to set QUOTED_IDENTIFIER ON, which is required for filtered indexes, indexed views and other features. SQLCMD initially sets QUOTED_IDENTIFIER OFF off by default for backwards compatibility.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.