Dear sir:
It shows the message:Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ')' when I run my procedure
Regards,
Shell Hu
Shell
As Kalman noted, it's recommended to debug dynamic sql using PRINT statement(s).
Also, it's a good practice to use your code within TRY/CATCH block(s) to find the root of errors.
BTW, I guess follow code will help you in this situation:
if ltrim(rtrim(@cols)) <> ''
begin
exec ('Select * from (select a.SDate ,sum(a.SLabor ) as LaborRequire
from (select a.SDate ,a.SLabor from ProductionSchedule a where a.SDate >='+ @QSDate +') a
group by a.SDate ) as a pivot (sum(LaborRequire) for SDate in (' + @cols + ')) as b')
end
Saeid Hasani [sqldevelop]
No comments:
Post a Comment