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

sql server programming

group:

Using IF statements in Queries


Re: Using IF statements in Queries Louis Davidson
10/1/2003 4:36:56 PM
sql server programming:
Use Case;

case when contract.type = 'Bilat' then 1 else 0 end as TypeCount

You may also want to cast this value. It will default to an integer.

--
----------------------------------------------------------------------------
-----------
Louis Davidson (drsql@hotmail.com)
Compass Technology Management

Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266


[quoted text, click to view]

Using IF statements in Queries Phil Atkinson
10/1/2003 11:11:14 PM
Hi - I am somewhat of a novice when it comes to SQL and I was wondering
if it possible to use an IF statement in a query.

My query looks something like this,

Select Contract.Amount, Contract.Type, Contract.Market
From Contract

Result Set

1200 Bilat GER
500 Cleared GER
250 Bilat NED

Basically what I would like to do is create a 4th column that would read:

IF(Contract.Type = 'Bilat',1,0) AS TypeCount

In other words for ever 'Bilat' a 1 would be produced or else a 0

Help appreciated

Phil Atkinson
AddThis Social Bookmark Button