July 12, 2015 at 8:57 pm
Hi,
I want to convert the rows and group into fixed columns format. Could you help me?
This is my table:
Plist consist QA, QB, Qc etc and T consist sets of numbers
PLIST T
QA 12, 14
QA 16, 18
QB 22, 24
QC 02, 06
QC 08, 09
QC 10,
Resulting in fixed 3 column query:
PLIST T1 T2 T3
QA 12, 14 16, 18
QB 22, 24
QC 02, 06 08, 09 10
Any helps appreciated.
Thank you.
Dave
July 13, 2015 at 7:47 am
Hi and welcome to the forums. What you are describing is often called a cross tab or pivot. Personally I prefer using the cross tab method instead of pivot because the syntax of PIVOT is very obtuse to me. You can read about the cross tab approach by following the links in my signature about converting rows to columns. If you have a set number of columns the static approach will work fine. If you don't know how many columns you will need to use the dynamic approach found in the second article.
If you run into any issue and need more help I will be happy to help. In that case, take a look at the first link in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 14, 2015 at 5:36 am
Thanks Sean for your advise. I will look into it and try.
Regards,
daven
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply