all groups > sql server programming > september 2003 >
You're in the

sql server programming

group:

Select Column Depending on Val in Other Column


Select Column Depending on Val in Other Column Jay
9/3/2003 6:50:16 PM
sql server programming:
In Table1 I have 3 column:

ProdID varchar
Price1 money
Price2 money

Data like so:

123, $50, $75
456, $8, $0
789, $67, $56
345, $32, $0
....

I need to select ProdID and Price(1 or 2) depending on if Price2 is $0. If
Price2 is $0 then I need to return Price1. So the result would be like so
(based on above data):


123, $75
456, $8
789, $56
345, $32

What would be the best, fastest approach to do this?

Thanks a lot.

Jay

Re: Select Column Depending on Val in Other Column Tom Moreau
9/3/2003 6:58:26 PM
Try:

select
ProdID
, case when Price1 =3D 0 then Price2 else Price1 end
from
MyTable

--=20
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
..
[quoted text, click to view]
In Table1 I have 3 column:

ProdID varchar
Price1 money
Price2 money

Data like so:

123, $50, $75
456, $8, $0
789, $67, $56
345, $32, $0
....

I need to select ProdID and Price(1 or 2) depending on if Price2 is $0. =
If
Price2 is $0 then I need to return Price1. So the result would be like =
so
(based on above data):


123, $75
456, $8
789, $56
345, $32

What would be the best, fastest approach to do this?

Thanks a lot.

AddThis Social Bookmark Button