Reputation: 17930
I have a table Part(No,Desc,Draw).
I want to return a list of all the parts in the table in this form :
Part Number| Description | Is Packed ? (Yes/No)|
------------------------------------------------
In the result set, the Is Packed header should be Yes if the Draw column is not null and No if otherwise.
I'm using PL/SQL.
I don't know how to do this.
Upvotes: 0
Views: 68
Reputation: 838226
Use CASE
:
CASE WHEN Draw IS NOT NULL THEN 'Yes'
ELSE 'No'
END AS column_alias
Upvotes: 1
Reputation: 70369
As an alternative to CASE
(see other answers) in this case you can use NVL2
:
SELECT No AS "Part Number", Desc AS "Description", NVL2 ( DRAW, 'YES', 'NO' ) AS "Is Packed" FROM PART
BTW: you should neve create a DB object (table/column...) with a name which is a reserved word (in you case Desc
) - this can lead to really strange things...
Upvotes: 2
Reputation: 37364
SELECT No AS "Part Number", Desc AS "Description",
CASE
WHEN Draw IS NOT NULL THEN 'Yes'
ELSE 'No'
END AS "Is Packed"
FROM Part
You might need to escape Desc
in field list since it's a reserved word.
Upvotes: 4