Monday, 13 May 2013

How can we compare two columns value in same table in MS Sql Server

How can we compare two columns value in same table in MS Sql Server


We have one table ExamScore 

StudentId
ExamScoreCT1
ExamScoreCT2
TotalMarks
1
87
75
100
2
68
77
100
3
76
91
100
4
88
56
100
we want to compare two compare two Columns  ExamScoreCT1 and ExamScoreCT2 of this table
we want to select greater marks between both of colums ExamScoreCT1 and ExamScoreCT2


query :


SELECT CASE  WHEN ex.ExamScoreCT1 >= ex.ExamScoreCT2  THEN ex.ExamScoreCT1  ELSE ex.ExamScoreCT2 END
FROM ExamScore as ex




0 comments:

Post a Comment