question

Arihant avatar image
Arihant asked

Convert rows into column and columns into rows without pivot

All I need is convert Column(A1/A2) into rows and rows(1 into Jan) into columns. Input: Here A1/A2 belongs to say A and they are calculated as A1/A2 for each month. Month A1 A2 B1 B2 C1 C2 1 120 60 40 80 120 120 2 50 50 40 20 60 30 3 50 25 40 10 90 30 I need below o/p without using pivot and unpivot O/P: X Jan(1 is denoting Jan) Feb Mar A 120/60(calculation:A1/A2) 40/80 120/120 B 50/50 40/20 60/30 C 50/25 40/10 90/30 I tried but my query is too long as I am using case and Union All three times each For A1 A2,B1 B2,C1 C2 etc. Can you pls help me out. Thanks in advance
sqltsqlsqlserver
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

are you using the PIVOT keyword or relying on the old-style pivot using CASE statements? the PIVOT syntax is more succinct, so you may not have problems with your query length if you use that. I wrote a short post on this a little over 10 years ago (old timer here!!!) - http://kenj.blogspot.com/2006/02/crosstab-pivot-queries.html Can you post the query you've been using?
0 Likes 0 ·

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.