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 |
|
netedk
Starting Member
11 Posts |
Posted - 2003-02-25 : 13:54:23
|
| I have the foll tables:table name: optionsoption_id option_display1 A2 B3 C4 D5 M6 N7 O8 PTable: field_valuesfld_id option_id recipient_id1 1 A12 6 A11 1 A22 5 A21 2 A32 8 A31 2 A42 8 A41 4 A52 8 A51 4 A62 7 A6Now I want to display the table results in the foll. fashion: A B C DM 1 0 0 0N 1 0 0 0O 0 0 0 1P 0 2 0 1Explanation: the options table has form options and the field_values table has user submitted values from a form. now in the reporting table I want to cross tab with field_id = 1 as column headers and fld_id =2 as row headers.I have tried a lot - but to no avail. Most articles on cross-tabs assume data to lie in diff. tables. But here data lies in the same table - so how do I go about it?? can this be done usingg T-SQL at all? any help will be greatly appreciated. Thanks a lot,DK |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-02-25 : 14:00:54
|
| Do you have a real world example? I can't see the forest for the trees with this one...It doesn't seem like your sample data supports what you're doing..sorry wish I could helpBrett8-) |
 |
|
|
netedk
Starting Member
11 Posts |
Posted - 2003-02-25 : 17:50:44
|
| Hi Brett,Sorry I forgot a field in the first table. I am putting my table structures again here:table: form_fields (this table stores the diff. fields in a form)fld_id fld_name1 what is your favorite color?2 what is your favorite means of transportation?table name: options (stores the predefined options for fields)option_id option_display fld_id1 red 12 blue 13 green 14 orange 15 car 26 boat 27 air 28 bus 2Table: user_values (stores the actual user responses)fld_id option_id respondent_id 1 1 A1 2 6 A1 1 1 A2 2 5 A2 1 2 A3 2 8 A3 1 2 A4 2 8 A4 1 4 A5 2 8 A5 1 4 A6 2 7 A6 Now I want to display the table results in the foll. cross-tabs fashion: Red Blue Green Orange Car 1 0 0 0 Boat 1 0 0 0 Air 0 0 0 1 Bus 0 2 0 1 Hope I was able to elaborate my problem much more clearly now.Thanks for any guidance you can provide.DK |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-02-25 : 18:06:54
|
| This should help:http://www.sqlteam.com/item.asp?ItemID=2955You'd have to join options to user_values twice, once as a color alias and again as a transport alias. I tried figuring out the join syntax but I can't see it yet. If I figure it out I'll post it, but you can probably figure it out pretty quickly. Once you do that, it would be passed as the @select parameter to the stored procedure. |
 |
|
|
|
|
|