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

help formatting data using SQL

Status
Not open for further replies.

welshone

Programmer
Jul 30, 2001
414
GB
Hello,

how can I do this in Oracle SQL....

I have the results looking like this ::

name dob preference type
dave 1/1/11 1 Q
dave 1/1/11 2 S
sarah 2/2/22 1 T
steve 1/1/12/ 1 B
steve 1/1/12/ 2 A
steve 1/1/12/ 3 Y

and so on.



how can I display the reults like :

name dob pref1 pref2 pref3 pref4
dave 1/11/12 Q S
sarah 2/2/22 T
steve 1/1/12 B A Y


any ideas?
thanks guys.
 
hello,
to do this I think I need to use case, but am getting an error, incorrect parenthesis when running the following :

SELECT FORENAME, SURNAME,
(CASE WHEN PREFERENCE = 1 THEN "TYPE" END) AS "PREF1",
(CASE WHEN PREFERENCE = 2 THEN "TYPE" END) AS "PREF2",
(CASE WHEN PREFERENCE = 3 THEN "TYPE" END) AS "PREF3"
FROM
MAINTABLE

TO SHOW :

forename surname pref1 pref2 pref3

thank you for any info.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top