Go Back   CodingForums.com > :: Server side development > MySQL > Other Databases

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-05-2005, 04:23 PM   PM User | #1
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
return conditional boolean as a field

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
Code:
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)
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 07-05-2005, 07:57 PM   PM User | #2
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
I think this'll work:

Code:
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.
Kid Charming is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:25 PM.


Advertisement
Log in to turn off these ads.