Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
richxyz
Starting Member
12 Posts |
Posted - 2007-08-30 : 15:46:02
|
I have a table that I need to pivot to make the data more readable for the user. The problem, you will see, is that Question3 has multiple answers (zero to 5 possible answers.)Here is the data of the sourceUserID QuestionID Answer 1 1 B11 2 B21 3 A1 3 B1 3 C2 1 ZZ2 2 abc2 3 1a2 3 1x The output needs to look like thisUserID Question1 Question2 Question31 B1 B2 A, B, C2 ZZ abc 1a, 1xI have an ugly cursor that does this and it is taking 5 hours to run. I'm wondering if anyone has a slicker way? |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-08-30 : 15:49:52
|
Where are you displaying this data to the user? You should simply return data from SQL with its usual multi-row output and format your data at your presentation layer however you'd like. SQL Server is a not a formatting tool, it is a database.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
richxyz
Starting Member
12 Posts |
Posted - 2007-08-30 : 16:01:15
|
I am copying and pasting the data into Excel. I will still have the problem (in Excel) with question 3. I don't know how I'd concantonate the multiple values into one cell. I can figure out how to do the pivot table - but can you offer a suggestion on collapsing the multiple answers of Question3 into one? |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
richxyz
Starting Member
12 Posts |
Posted - 2007-08-30 : 17:31:45
|
Thank you. This is very helpful! |
 |
|
|
|
|