Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Experts,

I have a tables for students records of subject wise. How can i get the record student wise and subject wise.

Ex:
Subject1 Subject2 ................N
Student1 Marks
Student2
.
.
.
N

XML
There Are Three Tables :

1 : Student : That have  Student Id and Student Name
2 : Subject : That Have Subject Id and Subject Name
3 : Student_Records : That have Student Id and Subject ID and Marks.


Now i want to generate the comparison record for all students and all subjects. Report will be in given format.

 <pre>
          Math         English     Art         Music   -----------------N
Student1   10             20        30           40
Student2   20            11         22           01
Student3   3             4           6            7
-
-
-
-
N</pre>




Thanks
Posted
Updated 23-Jan-12 4:51am
v2
Comments
OriginalGriff 23-Jan-12 3:53am    
Sorry, but that doesn't make much sense - your example seems to have two different forms of data in the same table.
Please try to explain your table (or tables) structure a little more clearly.
Use the "Improve question" widget to edit your question and provide better information.
[no name] 23-Jan-12 3:58am    
Yes You can say it we have two masters 1: Student 2 : Subject
And we are storing data in Students_Records table.

The Students and Subjects are dynamic that we can delete or add new.

Than How can we generate the record to analysis the Performance report according to all subjects.


1 solution

I think this will help you

SQL
DECLARE @StudentInfo AS TABLE
(
 Student NVARCHAR(50),
 Subject1 BIGINT ,
 Subject2 BIGINT ,
 Subject3 BIGINT ,
 Subject4 BIGINT 
)


INSERT INTO @StudentInfo 
SELECT 'Student1',54,42,50,62
Union
SELECT 'Student2',38,40,45,78



SELECT Student, Subject, Marks
FROM 
   (SELECT Student, Subject1, Subject2, Subject3, Subject4
   FROM @StudentInfo) p
UNPIVOT
   (Marks FOR Subject IN 
      (Subject1, Subject2, Subject3, Subject4)
)AS unpvt;
 
Share this answer
 
Comments
[no name] 23-Jan-12 4:01am    
In this have you have not fixed Students and subjects. Then How can i generate report for performance report .
RDBurmon 23-Jan-12 4:05am    
Could you please post your table structure ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900