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)
hii..frnds...i am unable to write a generalized syntax for the update delete insert statments..i mean that if i want to delete a selected row than i am able to do that by specifying the id number of that row,but for remaining ids it doesnt work..so that piece of generalization is what i want..plz help me
delete from student where rollno='12';
this is generally how we delete....and in generalized format
delete from student where rollno=@rollno;
but the above line is giving me error stating tht @rollno should be declared as a variable.
i am unable to solve it.....
You see we can give you a Solution, but now, your English is not good and you dont get into detail about your problem, you just shoot us with long incomplete statements. take your time and explain your problem and we will step by step help you solve your problem. and lastly you should post this in C# Forum noy here. But as you already done it here you might as well continue
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
I already answered your first post on this, I'm sorry if you don't understand but here it isagain:
The best option in my opinion is to use windows groups to limit user access. It still uses windows authentication so no password verification etc, and you can then grant explicit permissions to the group. You can deny permissions as well as grant them, so deny select, insert, update, delete on your tables and grant exec on the stored procs.
Its a standard way of doing it and easy to maintain by scripts.
The login to the application is wrote not in C# but SQL store procedures. I press a buttom that triggers a SP that manages the login. my connection strings have both no password and user.
From this I must assume you are alreay using windows authentication, so you need to set the table permissions as I said. This will prevent someone attaching to you database and seeing the tables. I'm not sure how to explain thsi any clearer, but try google for granting permissions in sql server, it may help your understanding.
Bob Ashfield Consultants Ltd
Last Visit: 31-Dec-99 19:00 Last Update: 2-Dec-22 4:07