My Table structure is look like this.....Code, Q1, Q2, Q3 and records are like...
Code Q1 Q2 Q3
1 Good Good Average
2 Poor Average Average
3 Good Excellent Average
4 Excellent Good Good
I need to write a single query, which will give result look like.
Excellent Good Average Poor
Q1 1 2 0 1
Q2 1 2 1 0
Q3 0 1 3 0
Actually, this table is used to get the feedback from the users. User has given their feedback by selecting options. I need the details that how many persons answered Excellent for Question1 (Q1), Question2 (Q2), etc...As well as How many answered Good for Q1,Q2,Q3, etc....I need this format. Please help me.
SQL Server has a Pivot/Unpivot syntax, I used the unpivot for this. If your using SQL server, then this should work for you.
,Sum(Case When Response = 'Excellent' Then 1 Else 0 End) as Excellent
,Sum(Case When Response = 'Good' Then 1else0 End) as Good
,Sum(Case When Response = 'Average' Then 1 Else 0 End) as Average
,Sum(Case When Response = 'Poor' Then 1 Else 0 End) as Poor
(Select Code, Q1, Q2, Q3
From <code>#t</code>) p
(Response For Question In
(Q1, Q2, Q3)) as unpvt
Group By Question
Just replace the #t (highlighted in the dark red) with your table name.
It you have a relationship setup between the 2 tables on the id column with the cascading delete property set, then deleting the records for one table will delete the corresponding records from the other table
I am creating a report in SQL Reporting Services 2005.
The data is coming from a stored procedure which has multiple select statements (multiple result sets).
When I bind the report with the dataset ,I am getting the data only from the first select statement (1st table), whereas I am getting the data from each select statement in the stored procedure.
Is there any way to get the data while designing the reports?
I want to display error message if any error occurs while executing my stored procedure(for debugging purposes). How to display an error message in stored procedure (I am using sql server 2005)