0

I have some insert statements in a .sql file.

I want to execute the insert statements via sqlcmd and tried to do it like this:

sqlcmd -S (localdb)\MSSQLLocalDB -i C:\BacklogItems\15298\dbo.ak_funktion_typ.Table.sql

Unfortunately, I get the following error:

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'S'.

What could be the problem with the -S?

According to https://www.mssqltips.com/sqlservertip/4924/execute-sql-server-script-files-with-the-sqlcmd-utility/ the I can provide the server name via this parameter...

I've made sure that the query is in the SQLCMD Mode.

Thanks in advance for any tips

11
  • Are you sure it's not talking about a syntax error in the .sql file? That's a SQL error message. If it were a problem with the command itself, you'd get a DOS/Windows error message Commented Oct 10, 2017 at 9:11
  • the insert statements in the .sql file are generated by the "Generate Scripts" wizard from the sql server management studio Commented Oct 10, 2017 at 9:12
  • still worth checking they're ok, and that there's nothing else wonky in the file. Try executing the statements directly in a SQL GUI. I'm 99.9% sure that the Windows command line doesn't generate "syntax error" reports Commented Oct 10, 2017 at 9:12
  • I just tried to execute the statements in the .sql file by hand and it worked without any problems Commented Oct 10, 2017 at 9:13
  • 1
    ah okay now I understand what you mean, sorry for the confusion. To execute it via sqlcmd-mode I have to write :r instead of sqlcmd. Thanks for your help, if you add it as answer, I'll accept it Commented Oct 10, 2017 at 9:25

1 Answer 1

4

The reason you are getting that error is because you need to execute sqlcmd in a Windows Command Prompt environment, not in a SQL editor environment such as SSMS. sqlcmd is a separate executable (.exe) utility which has some equivalence to a GUI such as SSMS, in that it is another type of client program for communicating with the database server. It is not a tool which is used within SSMS itself (or any other SQL client).

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.