sql - pivoting rows to columns in tsql -


I have the following sample data in the following table

  ID language question SubQuestion SubSubQuestion TotalCount Kulprasar 3 E 9 0 1 88527 73% 3 E 9 2 2 1 9 684 16% 3 E 9 323 9 60 11% 3 e 9 9 9 33 1%   

Let me In the row everything should be like this:

  id language TotalCount901 TotalPercent901 TotalCount902 TotalPercent902 TotalCount903 TotalPercent903 3E 88,527 73% 19,684 16% 12960 11%   

I Tired, but it is not ready to work for me.

I have made some assumptions based on your column names, but it seems that you Want to use something similar from This is applied to both UNIVIS and then a PIVOT to get the value in the column you requested:

 Select from  (Selection ID, Language, QL + Cast) (as the Varchar (10)) + cast (subsurface as Worker (10)) + Cast (Submitted Question as varchar (10)), Call value (Selection ID USRC unpivot (in (TOTALCOUNT, totalpercent)), language, artist (varchar (10)) as TOTALCOUNT, totalPercent, question, subquestion, yourtable (SubSubQuestion for col in [TotalCount901]) Value for the country col) srcpiv axis (max (value), [totalPercent901], [TotalCount902], [totalPountcent2], [TotalCount903], [totalPortcent903], [TotalCount909], [totalPercent909]))  Note: When  UNPIVOT  columns need the same datatype if they are not, then you get to convert the datatype to the same type of convert / Cast will be required.  

If you have an unknown number to converge, then you can use the DirectX SQL:

  DECLARE @query AS NVARCHAR (MAX), @ colsPivot As NVARCHAR (MAX) selections @colsPivot = STUFF (select ',' + 'QUOTENAME (c.name + cast (Question as varchar (10)) + cast (subquestion (10) as varchar) SubSubQuestion T as the cast (your tablets varchar (10))) apply sys.columns such as cross c where C.object_id = object_id ('yourtable') and C.name c.name ('TOTALCOUNT', ' TotalPercent ') group, t.question, t.subquestion, t.sububquestion XML path (' ', t For EEPE, order by T. SBS Question Price ('.', 'NVHAR (Max)', 1,1, '') @ Set = Select from * (select ID, language, col + cast (varchar) As the question (10)) + cast (subquestion as varchar (10)) + cast col, from (id, language, select value of artists (varchar (10) SubSubQuestion as the form of (TOTALCOUNT varchar) (10) Total Count, Total Effective, Question, Submission, Subscription from your Bandh) USRC Univot (Value for Columns (Total Number)   

Performed x (value) 'p' for colonel ('korea') for Colonel in SourcePort Pivot (MA) ('+ @ ColsPivot +') / P>

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -