Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grouping by the result of a case statement 3

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Hello all --

How do I group by the result of a case statement???

ex)
SELECT typeRRS = CASE WHEN demo.typeRRS = 1 OR demo.typeRRS = 2 THEN 1 ELSE 3 END
FROM tableName
GROUP BY typeRRS

This statement groups the result set by demo.typeRRS, not the resulting 1 or 3 that comes out of the statement...

Thanks! :)
Paul Prewett
penny.gif
penny.gif
 

Use the CASE statement in the GROUP BY clause.

SELECT typeRRS = CASE WHEN demo.typeRRS = 1 OR demo.typeRRS = 2 THEN 1 ELSE 3 END
FROM tableName
GROUP BY CASE WHEN demo.typeRRS = 1 OR demo.typeRRS = 2 THEN 1 ELSE 3 END
Terry Broadbent
Please review faq183-874.

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top