We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
SELECT Name = CASE WHEN G.Grade >7 THEN S.Name ELSE NULL END, G.Grade , S.Marks FROM Students S
INNER JOIN Grades G ON S.Marks >= G.Min_Mark AND S.Marks <= G.Max_Mark
ORDER BY Grade DESC,Name,Marks;
The Report
You are viewing a single comment's thread. Return to all comments →
priyanshu281, if it is having trouble with NULL and order, try converting the null into a 0.
The orderby line becomes:
order by G.Grade DESC, ISNULL(name, 0), Marks
WORKED FOR ME
SELECT Name = CASE WHEN G.Grade >7 THEN S.Name ELSE NULL END, G.Grade , S.Marks FROM Students S INNER JOIN Grades G ON S.Marks >= G.Min_Mark AND S.Marks <= G.Max_Mark ORDER BY Grade DESC,Name,Marks;
I can't use this script. In the name field, its printed 1, instead of the correct name. This is the output returned:
in place of 'SELECT NAME = CASE' in first line, use 'SELECT CASE' because I think the former one is evaluating in 1 and 0(boolean)
why should we use case..? pls explain..
It adds a conditional data value for the name column. The name of the student in the current row or NULL