I have below dynamic query:
SET @DynamicPIVOT = 'SELECT * FROM (
SELECT StudentId, IsForeNoon,Date as date1 FROM Attendance_FN_AN
) as Books
PIVOT (
Count(IsForeNoon) FOR date1 IN (' + @cols + ')
) as Result'
END
exec @DynamicPIVOT;
When I execute the above dynamic query, single quotation not removed from the front and last so that The Issue come for
The name 'SELECT * FROM (
SELECT StudentId, IsForeNoon,Date as date1 FROM Attendance_FN_AN
) as Books
PIVOT (
Count(IsForeNoon) FOR date1 IN ([2015-04-16])
) as Result' is not a valid identifier.
Any solution for this?