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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Distinct for a Condition B-)

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
My query returns records as such:

DOCNUMBER DOCTYPE
123 ABC
123 DEF
123 GHI
123 POD

I WANT TO COMBINE THE 3 ROWS FOR DOCNUMBER 123 AND DOCTYPE
BEING ABC, DEF, GHI INTO ONE ROW SAYING DOCTYPE 'ABC,DEF,GHI'. I want to keep row 123 with Doctype POD as a row by itself.
 
Please supply more info, then someone may be able to assist.
 
My query returns records and are displayed in my report as below:

DOCNUMBER DOCTYPE
123 ABC
123 DEF
123 GHI
123 POD

I WANT TO COMBINE THE 3 ROWS FOR DOCNUMBER 123 AND DOCTYPE
BEING ABC, DEF, GHI INTO ONE ROW SAYING DOCTYPE 'ABC,DEF,GHI'. I want to keep row 123 with Doctype POD as a row by itself.

I want the records to be displayed as such:

DOCNUMBER DOCTYPE
123 ABC, DEF, GHI
123 POD

Basically the DOCTYPES ABC, DEF, and GHI belong together on one row, but the POD belong on a separate line.


 
So something like this?

SELECT MAX(DOCNUMBER) AS DOCNUMBER, CASE WHEN DOCTYPE IN ('ABC', 'DEF', 'GHI') THEN 'ABC, DEF, GHI' ELSE DOCTYPE END AS DOCTYPE FROM ???? GROUP BY CASE WHEN DOCTYPE IN ('ABC', 'DEF', 'GHI') THEN 'ABC, DEF, GHI' ELSE DOCTYPE END


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top