...

View Full Version : return conditional boolean as a field



ghell
07-05-2005, 04:23 PM
im looking for a way to check if the NAME field is in an array, in the where clause this would look like this:

where name in ('a', 'b')

but i just want it to return it as it currently is but have an extra field returned true or false (tbh it doesnt matter how its returned, it just needs to be different depending on the result)

for example this code doesnt work
select name, gender, (name in ('mike', 'dave')) as blnIsMikeOrDave from sometable where gender = 'm'this is for use in an asp page and i would prefer a single line than a stored proc for it (ms sql server 2000 btw)

Kid Charming
07-05-2005, 07:57 PM
I think this'll work:



SELECT
name
,gender
,CASE
WHEN name IN ('mike','dave') THEN 1
ELSE 0
END
AS bln
FROM
table


Though it may also be worth trying the query you posted without the bounding parentheses -- I don't have an mssql server around to test, but I would think you could simply capture the return value of name IN ('mike','dave') without having to use CASE.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum