Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

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

Asked by Gareth Beacham Sep 7, 2021 4.5K views 1 answer
Share

About this question

In this code I am converting the subjects(columns) English , Hindi , Sanskrith , into rowsDECLARE @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 . How do I use SQL Server for XML Path?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.