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 |
|
MickeyD
Starting Member
4 Posts |
Posted - 2006-04-03 : 13:15:37
|
| Hi,I have to generate a daily report of survey answers by users? My question is there a way to reformat the query so it generates a table or report with it showing the rows as columns instead.Here is my initial query.SELECTdbo.Reporting_SurveyAnswers.DateCreated AS DateCreated,dbo.Reporting_SurveyAnswers.questionid AS QuestionID,dbo.Reporting_SurveyAnswers.surveyid AS SurveyID,dbo.Reporting_SurveyQuestions.ordernumber AS OrderNumber,dbo.Reporting_SurveyAnswers.userid AS UserID,dbo.Reporting_User.LastName1 AS LastName,dbo.Reporting_User.FirstName AS FirstName,dbo.Reporting_SurveyQuestions.QuestionText AS QuestionText,dbo.Reporting_SurveyAnswers.QuestionAnswer AS QuestionAnswerFROMdbo.Reporting_SurveysINNER JOIN dbo.Reporting_SurveyQuestionsON dbo.Reporting_Surveys.surveyid = dbo.Reporting_SurveyQuestions.surveyidINNER JOIN dbo.Reporting_SurveyAnswersON dbo.Reporting_SurveyQuestions.QuestionID = dbo.Reporting_SurveyAnswers.QuestionIDINNER JOIN dbo.uvwReporting_UserON dbo.Reporting_SurveyAnswers.userid = dbo.uvReporting_User.useridWHEREdbo.uvReporting_SurveyAnswers.surveyid = 1125Order by dbo.Reporting_SurveyAnswers.DateCreated,dbo.Reporting_SurveyQuestions.ordernumberSelect dbo.Reporting_SurveyQuestions.ordernumber AS OrderNumber, dbo dbo.Reporting_SurveyQuestions.QuestionText AS QuestionTextTo complicate matters, some of the users did not answer some of the questions and some of the questions are duplicated in the rows because the database assigned them one answer each.Example. Question 18 says "Name all the industries you have worked in. Check all that apply.What happens is lets say the user checks 4 different boxes. In the query results, it will show 4 rows with question 18 with each answer they checked off.Any help would be appreciated.ThanksThe Accidental Tourist |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-04-03 : 13:42:24
|
| Do a search for Crosstab or dynamic crosstab on the main site or in the forum. That should point you in the right direction.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
|
MickeyD
Starting Member
4 Posts |
Posted - 2006-04-03 : 13:52:53
|
| Hi MichaelP.Thanks. BTW, I accidentally added these 2 syntax lines at the bottom of my query by mistake.Select dbo.Reporting_SurveyQuestions.ordernumber AS OrderNumber, dbo dbo.Reporting_SurveyQuestions.QuestionText AS QuestionTShould be disregarded.I am checking the cross-tab but I am still fuzzy how to integrate it within my query.The Accidental Tourist |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|