I am trying to run a .sql file in SQL Server Management Studio using this command
EXEC xp_cmdshell sqlcmd -s '127.0.0.1' -d MyDB -i 'C:\Data\ProcessedSQL\ReversalFile1.sql'
but I am getting an error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'
Can someone assist me please?
Update Edit:
To be clear, I am only starting to use SQL Server.
I have several sql files in one folder and I was hoping to run a query window in SSMS to run several sql files one after another as follows:
Execute file1
Execute file2
Execute file3
The Files are being generated out of another system by a DBA.
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i CoreLibLUT_Insert_VoiceOverride.sql -o CoreLibLUT_Insert_VoiceOverride.out. Generally, I use this in batch script in which I write the names of sql files in a proper sequence then give the whole package to client. they run this batch file to upgrade the DB to newest version.