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 |
|
gotafly
Yak Posting Veteran
54 Posts |
Posted - 2005-02-16 : 22:30:47
|
Out of the 3 tables below. I need to get a tabular report like this First Name Last Name Email Can you receive HTML email Address State Zip Tom Thompson xxxx@xxxxxxxx.com Yes 575 mystreet Rd AK 14525steve Smith aaaa@aaaaaaaa.com No 575 double Dam Rd AL 13323 table 1 QuestionID ModID Question 18 362 First Name 19 362 Last Name 20 362 Email 21 362 Can you receive HTML email 23 362 Address 24 362 State 25 362 Zip Table 2 Resultid QuestionID OptionD OptionTextboxValue SurveyResultID modid2051 18 -55 Tom 140 3622052 19 -55 Thompson 140 3622053 20 -55 xxxx@xxxxxxxx.com 140 3622055 21 47 140 3622056 23 -55 575 mystreet Rd 140 3622057 24 52 140 3622058 25 -55 14525 140 3622059 18 -55 steve 140 3622060 19 -55 Smith 140 3622061 20 -55 aaaa@aaaaaaaa.com 140 3622063 21 48 140 3622064 23 -55 575 double Dam Rd 140 3622065 24 53 140 3622066 25 -55 13323 140 362 Table3 optionid Que stionID optionText41 18 firstName43 19 lastName45 20 emailAdd47 21 Yes48 21 No50 23 address52 24 AK53 24 AL55 25 zip |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
gotafly
Yak Posting Veteran
54 Posts |
Posted - 2005-02-17 : 08:13:44
|
| Sorry Guys. I am new to crosstabs. I get this error:Server: Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value 'David' to a column of data type int.SELECT SurveyResultID, SUM(CASE QuestionID WHEN 18 THEN OptionTextboxValue ELSE 0 END) AS FirstName, SUM(CASE QuestionID WHEN 19 THEN OptionTextboxValue ELSE 0 END) AS LastName, SUM(CASE QuestionID WHEN 20 THEN OptionTextboxValue ELSE 0 END) AS Address, SUM(CASE QuestionID WHEN 21 THEN OptionTextboxValue ELSE 0 END) AS City SUM(CASE QuestionID WHEN 22 THEN OptionTextboxValue ELSE 0 END) AS StateFROM FormCreator_ResultsGROUP BY SurveyResultIDGO |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-17 : 08:31:53
|
well you're OptionTextboxValue is of type varchar which you can't sum.maybe you need to replace it with OptionID ??Go with the flow & have fun! Else fight the flow |
 |
|
|
gotafly
Yak Posting Veteran
54 Posts |
Posted - 2005-02-17 : 13:21:57
|
| I got the following to work, but I somehow have to do a join on another table to get the state textSELECT SurveyResultID, MAX(CASE QuestionID WHEN 18 THEN OptionTextboxValue ELSE '' END) AS FirstName, MAX(CASE QuestionID WHEN 19 THEN OptionTextboxValue ELSE '' END) AS LastName, MAX(CASE QuestionID WHEN 20 THEN OptionTextboxValue ELSE '' END) AS Address, MAX(CASE QuestionID WHEN 21 THEN OptionTextboxValue ELSE '' END) AS City, MAX(CASE QuestionID WHEN 22 THEN OptionTextboxValue ELSE '' END) AS StateFROM FormCreator_ResultsGROUP BY SurveyResultID |
 |
|
|
|
|
|
|
|