Sample Header Ad - 728x90

Please explain what does "for xml path(''), TYPE) .value('.', 'NVARCHAR(MAX)')" do in this code

11 votes
2 answers
48997 views
**In this code I am converting the subjects(columns) English , Hindi , Sanskrith , into rows** DECLARE @colsUnpivot AS NVARCHAR(MAX), @query AS NVARCHAR(MAX) select @colsUnpivot =stuff( (select ',' + quotename (C.name) from sys.columns c where c.object_id = OBJECT_ID('dbo.result2') for xml path(''), TYPE) .value('.', 'NVARCHAR(MAX)'), 1, 8, '' ); print @colsunpivot select @query = 'select Name, Subject,Marks from result2 unpivot ( marks for subject in (' + @colsunpivot + ')) as tab' exec sp_executesql @query; *Please explain what does* **for xml path(''), TYPE) .value('.', 'NVARCHAR(MAX)') do here .**
Asked by Harish Kumar (165 rep)
May 21, 2018, 09:47 AM
Last activity: Feb 24, 2022, 10:19 PM