tsql - How to Pivot on caption? -


I am trying to pivot the rows in columns with Tsql and also end the tap. How do I do this? My current query:

  IF OBJECT_ID (N'tempdb .. # test_data ') Tap drop table #test_data Table #test_data (question_caption varchar (max), [0] varchar (max), [ Enter the #test_data value ('q1', 'abc', tap, faucet, zero) * #test_data value 'Q2', enter varchar (max), [2] varchar (max), [3] varchar (max), [3] Enter the #test_data value ('q3', tap, tap, 'd', null) in the form of the #test_data value ('q4', tap, tap, tap, 'jacqual'), tap, tap, 'df', tap, null) In the form of PivotTable  

output ([0], [1], [2], [3]) for question_caption, select #test_data from smoke (maximum [0]) * :

  question_caption 0 1 2 3 q1 ABC tap nail faucet Q2 faucet DRF cord faucet Q3 Nail faucet Nail Q4 Nail nail null JQUAL  

What do I need:

  q1 Q2 q3 q4 aBC def ghi jkl  

How can I get this? The error in the above query is: Message 265, Level 16, State 1, row 4 PIVOT operator specified column name "0" conflicts with existing column name in PIVOT argument.

I have tried several pivotal examples, but all of them got an error or another result.

You can get a simple maximum case :

 < Select the code> [q1] = max (when case_caption = 'q1' then ends [0] and ends), [q2] = max case when question_caption = 'q2' then ends [1] and tap), [ Q3] = max (case when question_caption = 'q3' then ends [2] and ends), [q4] = max (in case case_caption = 'q4' again [3] and tap end) #test_data  

or axis:

  from [q1], [q2], [q3] [q4] from ([q1]) (q ) To #te (from maximum, V) smoke (C, V) (Question, Capitol, section), ([0], [1], [2], [3]) St_data) [Q2], [q3], [q4])  

Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

python - mayavi mapping a discrete colorbar on a surface -