Click here to Skip to main content
16,016,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai friends,
i have two table
1.studentgrade
fields:stid stname regno subjec1 subjec2 subjec3 subjec4
1 xxxx 125 a b a rsa
2.subject:
fields: subjectcode subjecname
subjec1 c
subjec2 c++
subjec3 java
subjec4 .net

There is no relationship between these two tables.
But i need the result table as follows
subjectcode subjectname grade result
subjec1 c a pass
subjec2 c++ b pass
subjec3 java a pass
subjec4 .net rsa fail

what is the query for getting this result?.
Posted
Comments
Member 8915674 2-May-12 6:33am    
@karthik harve
can u give answer for this query?
to get student id who passed in all subjects in all the three years?

1 solution

Hi,
Try this query

SQL
SELECT SU.SubjectCode, SU.SubjectName,
 CASE WHEN SU.SubjectCode='Subject1'
         THEN (SELECT Distinct Subject1 FROM StudentGrade)
 CASE WHEN SU.SubjectCode='Subject2'
         THEN (SELECT Distinct Subject2 FROM StudentGrade)
 CASE WHEN SU.SubjectCode='Subject3'
      THEN (SELECT Distinct Subject3 FROM StudentGrade)
 CASE WHEN SU.SubjectCode='Subject4'
      THEN (SELECT Distinct Subject4 FROM StudentGrade)
 ELSE NULL END AS 'Grade',
 CASE WHEN Grade IN ('a','b') THEN 'Pass' ELSE 'Fail' END AS 'Result'
 FROM Subject SU


Hope it works
 
Share this answer
 
Comments
baskaran chellasamy 20-Apr-12 7:52am    
thanks for reply ..

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