You have delimit a single quote for
LIKE
:
GROUP BY Date DECLARE @query VARCHAR(8000) SET @query = ' SELECT * FROM (SELECT Name , Code, Section, Date FROM Absence) up PIVOT (COUNT() FOR Date IN (' + @columns + ')) AS p WHERE Section LIKE ''A'' ' EXECUTE(@query)