1

I'm currently trying to get a SQL script working for SQL Server 2005. I'm using SQLCMD to execute the script and it fails giving me an "Error: Syntax error at line 7 near command ':r'" error.

The script:

--Main Script--
SET NOCOUNT ON
GO

:on error exit

:r C:\Documents and Settings\ZSmith\My Documents\Scripts\CreateDatabase
:r C:\Documents and Settings\ZSmith\My Documents\Scripts\CreateTables

I can provide the other SQL scripts if needed but they function fine on their own. I'm just trying to automate the entire process.

1
  • Why the downvote? Could you at least tell me what I'm doing wrong? Commented Jul 3, 2013 at 15:54

1 Answer 1

2

From what I know, you need to

  • put the SQL file name into double quotes - especially if the path contains spaces!
  • include the .sql extension on the file name

Try this:

:r "C:\Documents and Settings\ZSmith\My Documents\Scripts\CreateDatabase.sql"
:r "C:\Documents and Settings\ZSmith\My Documents\Scripts\CreateTables.sql"
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.