![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
This is how the data is organized: vID Answer 12 Satisfied 12 Marketing 12 Yes 15 Dissatisfied 15 Technology 15 No 32 Strongly Dissatisfied 32 Marketing 32 Yes What I need to do is pull a recordset which each vID is a single row and each of the answers is a different field in the row so it looks something like this vID Answer1 Answer2 Answer3 12 Saitsfied Marketing Yes etc... I can't quite get my mind wrapped around this one. |
#3
| |||
| |||
|
|
Examples:http://builder.com.com/5100-6388_14-6143761.html PIVOT will only work if you have SQL SERVER 2005 otherwise you will use the CASE method. - Show quoted text - |
#4
| |||
| |||
|
|
Thanks for the link. I do only have SQL Server 2000 so the PIVOT is out. Looks like I will be doing some CASE statements. I'm new at this. Do you know the general syntax I would use using the above example to get this rolling? On Mar 29, 1:15 pm, "Jason Lepack" <jlep... (AT) gmail (DOT) com> wrote: Examples:http://builder.com.com/5100-6388_14-6143761.html PIVOT will only work if you have SQL SERVER 2005 otherwise you will use the CASE method. - Show quoted text -- Hide quoted text - - Show quoted text - |
#5
| |||
| |||
|
|
Thanks for the link. I do only have SQL Server 2000 so the PIVOT is out. Looks like I will be doing some CASE statements. I'm new at this. Do you know the general syntax I would use using the above example to get this rolling? |
#6
| |||
| |||
|
|
I can't quite get my mind wrapped around this one. From your example, the three answers seem to be drawn from different domains: |
#7
| |||
| |||
|
|
I can't quite get my mind wrapped around this one. From your example, the three answers seem to be drawn from different domains: customer_status, department, response Therefore, you should have seperate columns for them from the start and get rid of this non-table completely. This thing never made it to 1NF. YOu also semto assume that a table has an ordering, so that talking about first, second and third anssers makes sense -- it doe snot. I'm confused Joe... what's deer mucus got to do with this table. |
#8
| |||
| |||
|
|
I can't quite get my mind wrapped around this one. From your example, the three answers seem to be drawn from different domains: customer_status, department, response Therefore, you should have seperate columns for them from the start and get rid of this non-table completely. This thing never made it to 1NF. YOu also semto assume that a table has an ordering, so that talking about first, second and third anssers makes sense -- it doe snot. We can make some wild guesses about using CASE expressions to put your vague, generic answers into categories, but that is not the real problem. SELECT v_id, MAX (CASE WHEN answer IN ('yes', 'no') THEN answer ELSE NULL END) AS response, etc. FROM Foobar GROUP BY v_id; The CASE expressions would be converted into CHECK () constriants in proper DDL. |
#9
| |||
| |||
|
|
VoterID AnswerText AnswerID 5 Comments here 2058 5 <NULL> 2057 5 <NULL> 2059 AnswerID is found in the Answer table which corresponds (in this case) to 2057="Technology" and 2059="Satisfied" What I need is one recordset with the following format. VoterID Department Rating ---------- ----------------- ------------ 5 Technology Satisfied |
#10
| |||
| |||
|
|
Matt F wrote: VoterID AnswerText AnswerID 5 Comments here 2058 5 <NULL> 2057 5 <NULL> 2059 AnswerID is found in the Answer table which corresponds (in this case) to 2057="Technology" and 2059="Satisfied" What I need is one recordset with the following format. VoterID Department Rating ---------- ----------------- ------------ 5 Technology Satisfied Insert standard "post the CREATE TABLE statement for the Answer table" rant here. Assuming that it looks something like this: AnswerID | AnswerType | AnswerValue ---------+------------+------------ 2057 | Department | Technology 2059 | Rating | Satisfied then you can do: select va.VoterID, ad.AnswerValue as Department, ar.AnswerValue as Rating from VoterAnswers va join Answer ad on va.AnswerID = ad.AnswerID and ad.AnswerType = 'Department' join Answer ar on va.AnswerID = ar.AnswerID and ar.AnswerType = 'Rating'- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |