Reputation: 53
While I am executes the Stored procedures :
Exec [usp_SummaryReport] 77,1,'[Name]','2014-10-06 11:45:21.170','2014-10-06 11:45:21.170',[Name]
I am getting this error
Incorrect syntax near '-'
Thank you all. I got it corrected. It's an issue with value passing.
Upvotes: 1
Views: 2203
Reputation: 5808
As above suggested, please confirm that you create sqlscript dynamically and then execute?. If yes, then to solve just append this code before execute the script.
...... statement
print @query
EXEC sp_executesql @query
....
In SSMS, in message window, you can get the exact query witch give the issue. You can copy and past in new query window, modify it and finally replace in main sp's sql script.
Upvotes: 1
Reputation: 391456
Your procedure is building up SQL dynamically by concatenating pieces of it.
You would not get this type of syntax error if you didn't because the procedure was syntax-checked when it was created. The only possibility left is for the procedure to create some SQL itself and try to execute it.
This SQL, built dynamically, is what is giving you this error. Without seeing the actual code it is impossible for us to say why this SQL gives you this error.
Most likely you are prone to SQL injection by trying to concatenate the dates directly into the SQL instead of using parameters, but we have no evidence of this.
Upvotes: 0