User-49671077 posted
I need the using following SQL query to bind (GridView) using asp.net/vb.net.
SELECT DISTINCT datein INTO #Dates
FROM AttnEmployee
ORDER BY datein
-- a comma seperated value string from the dates in #Dates
DECLARE @cols NVARCHAR(4000)
SELECT @cols = COALESCE(@cols + ',[' + CONVERT(varchar, datein, 106)
+ ']','[' + CONVERT(varchar, datein, 106) + ']')
FROM #Dates
ORDER BY datein
-- Building the query with dynamic dates
DECLARE @qry NVARCHAR(4000)
SET @qry = 'SELECT * FROM (SELECT sid,datein,whours FROM AttnEmployee)emp PIVOT (MAX(whours) FOR datein IN (' + @cols + ')) AS stat'
-- Executing the query
EXEC(@qry)
-- Dropping temporary tables
-- DROP TABLE #Dates
Thanks