Now I want to Add all the GLH that are < 300, between 300-340 and 350+ so output will look like
(comments are locked)
|
|
Try this: However, if you have to have the data in that order, then that's a little more complicated: In both answers, what we're doing is using a WITH statement to create a CTE (Common Table Expression). This allows us to create an intermediate pseudo-table which holds the results of the initial select statement (in my case, from a table variable, in your case from a base table). This particular SELECT statement differs from yours in that I'm transforming the data into something that is more obviously related to the output you require - replacing GLH values with your grade band labels, for example - and (in the second example) also setting up a column for sorting based on the same cases. Note that the second example brings the data transformation up into the CTE declaration to make the final SELECT statement easier to read. I could also have done this with the first example... Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'ELSE'. THIS IS THE ERROR MESSAGE I RECIEVE
Sep 17 '12 at 02:58 PM
Mamzy
What is your query?
Sep 17 '12 at 03:00 PM
ThomasRushton ♦
Sep 17 '12 at 03:08 PM
Mamzy
THANKS FOR YOUR HELP BY THE WAY
Sep 17 '12 at 03:09 PM
Mamzy
Ah, I see what you've done. You've managed to get the CASE block slightly muddled. The SELECT ... CASE ... statement works like this: or In your case, I would suggest that you need to use:
Sep 17 '12 at 04:01 PM
ThomasRushton ♦
(comments are locked)
|

