Tuesday, 3 January 2012

How to get row column values as row headers in sql server

DECLARE @PivotColumnHeaders VARCHAR(MAX)
SELECT @PivotColumnHeaders = COALESCE(@PivotColumnHeaders + ',[' + cast(A.FieldName as varchar) + ']','[' + cast(A.FieldName as varchar)+ ']')
FROM dbo.tablename A -- where ID =5
print @PivotColumnHeaders

No comments:

Post a Comment