Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 IF or CASE Statement in SELECT

Author  Topic 

rwlopez
Yak Posting Veteran

80 Posts

Posted - 2006-11-14 : 13:08:57
Is there a way to use an IF or CASE statement within the SELECT statement of a query.

For
Example

SELECT SalesPersonID, SalesPersonID, IF(SalesRegion = 'CA','Y','') AS CaliforniaSalesperson
FROM SalesPerson

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-14 : 13:10:55
Have you tried to search SQLTeam and put in effort yourself? No...

SELECT SalesPersonID, SalesPersonID, CASE WHEN SalesRegion = 'CA' THEN 'Y' ELSE 'N' END AS CaliforniaSalesperson
FROM SalesPerson


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-15 : 09:59:07
Note that IIF will work in Access. CASE WHEN is its sql server equivalent

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -