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

IF statements within Select Statement

Status
Not open for further replies.

NEveritt

MIS
Dec 30, 2002
25
GB
Is it possible to have conditions within the select part of the query?

I.e. the data I want in column is a yes or no for each row of returned data. This would depend on a formula and condition.

Is it possible and how? (SQL 2000)

I do not mean an If..else with different queries.

N
 
Hi,

Have a look at CASE stmnts in SQL Books online...

SELECT CASE fldname When 'Apple' then 'Yes' else 'No' End YesNoFld from TBL

Hope it helps

Sunil
 
In SQL the If/Else is provided by the CASE statement. See Books Online for details. Here is an example:

Code:
SELECT flight_number,
       CASE
          WHEN seats_available > 0 THEN 'Yes'
          ELSE 'No'
       END AS "Possible Connection"
FROM flights
WHERE date_departure BETWEEN '04/20/2003' AND '04/21/2003'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top