Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Original
  2. RecordKey Name Section1_Product Section1_Code Section2_Product Section2_Code ......
  3. 1 a ff 22
  4. 2 b gg 22
  5. 3 c hh 33
  6.  
  7.  
  8. RecordKey Name Section Product Code ......
  9. 1 a 1 ff 22
  10. 1 a 2
  11. 2 b 1 gg 22
  12. 2 b 2
  13. 3 c 1 hh 22
  14. 3 c 2
  15.  
  16. SELECT RecordKey
  17. ,Name
  18. ,'Num_of_Sections' = ROW_NUMBER() OVER (PARTITION BY RecordKey ORDER BY ID)
  19. ,Product
  20. ,Code
  21. FROM (
  22. SELECT RecordKey, Name, Section1_Product, Section1_Code, Section2_Product, Section2_Code FROM Table
  23. ) M
  24.  
  25. UNPITVOT (
  26. Product FOR ID IN (Section1_Product, Section2_Product)
  27. ) p
  28.  
  29. UNPIVOT (
  30. Code FOR CO IN (Section1_Code, Section2_Code)
  31. ) c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement