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

Conditional Field in SELECT 2

Status
Not open for further replies.

BoulderBum

Programmer
Jul 11, 2002
2,179
US
I want to do something like:

Code:
SELECT a, b, ( c ) AS d
FROM table

where "c" would be a conditional statement like:

Code:
IF x IS NOT NULL AND y IS NOT NULL
    C = 'yes'
ELSE
    C = 'no'

Is what I want to do possible? How do I do it?
 
try this...

SELECT a, b,
case
when x is not null and y is not null then 'yes'
else 'no'
FROM table

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
You need a Case selection/substtution.
Select a,
b,
Case when x IS NOT NULL AND y IS NOT NULL
Then 'Yes'
Else 'No'
End As C,
D
From mytable

See BOL and CASE
MikeD

 
darn left off the "end"

SELECT a, b,
case
when x is not null and y is not null then 'yes'
else 'no'
end as C
FROM table

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top