Microsoft
Software
Hardware
Network
Question : Complex SQL Statement Help
I have a table that has survey results. The table structure is the followin
SurveyID SurveyMonth Q1 Q2 Q3 Q4 Q5
10 Jun2009 E E G F B
11 Jun2009 G E B G E
12 May2009 E G G B E
13 May2009 B G B E N
Ok each question has a possibe of 5 answers (E,G,B,P,N) I need a sql statement that would count the number of answers in each question for which ever survey(jun2009 or may2009) I want to report on. So the report will look like this
May2009 survey
E G B P N
question 1 1 0 1 0 0
question 2 0 2 0 0 0
question 3 0 1 1 0 0
question 4 1 0 1 0 0
question 5 1 0 0 0 0
Can I get a single sql statement to give me the data the way I need it, or do I have to pull all data for the survey and then use vb to loop through and do counts in some way. A suggestion would be greatly appreciated.
Answer : Complex SQL Statement Help
If you need to get this using SQL syntax, you have to use unions (single union for each question), however it will be rather hardcoded. Which DBMS you are using?
Random Solutions
Select MAX(ISNULL(variable, 0)) is returning NULL when it should be returning 0
Client laptops slow boot up, stuck on applying computer settings for a few minutes
Ms Access Query using LAST as criteria to find a record not working and bringing RANDOM Restuls
Are Dell PCs with same OEM number LEGAL ?
How to get local IP of Windows CE device.
Event 10016, DistributedCOM
How do I differentiate font format within the same Text Box in a form using Access 2007?
Trouble inserting date into Access 2003 database from Excel VBA using SQL
MsgBox firing twice during OnCurrent event ???
How can I send an email in MS Access 2007 with a report as a .pdf attachment?