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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query for "is value in set"?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

KilpAr
Yak Posting Veteran

80 Posts

Posted - 01/28/2013 :  05:37:48  Show Profile  Reply with Quote
What is the correct syntax for this:

SELECT 1 IN(2,3,4) AS IsInSet

So plain and simply I want to know whether the value is there or not.

The actual use for this will be for determining whether a given project is an internal or external project to a given user. I have a table allocations like
USER PROJECT
1 2
2 1
3 2
1 1

from which I want to extract info like "User 1, Project 2 => Internal (because such a pair is in the table). User 3, Project 1 => External (because no such pair is in the table)."

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 01/28/2013 :  05:46:47  Show Profile  Reply with Quote
you can use left join for that


SELECT *,
CASE WHEN a.User IS NOT NULL THEN 'Internal' ELSE 'External' END
FROM YourTable  t
LEFT JOIN allocations a
ON a.USER = t.User
AND a.Project = t.Project


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

KilpAr
Yak Posting Veteran

80 Posts

Posted - 01/28/2013 :  05:52:06  Show Profile  Reply with Quote
Ah, ok. Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 01/28/2013 :  06:13:05  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000