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.
Author |
Topic |
KilpAr
Yak Posting Veteran
80 Posts |
Posted - 2013-01-28 : 05:37:48
|
What is the correct syntax for this:SELECT 1 IN(2,3,4) AS IsInSetSo 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 likeUSER PROJECT1 22 13 21 1from 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
52326 Posts |
Posted - 2013-01-28 : 05:46:47
|
you can use left join for thatSELECT *,CASE WHEN a.User IS NOT NULL THEN 'Internal' ELSE 'External' ENDFROM YourTable tLEFT JOIN allocations aON a.USER = t.UserAND a.Project = t.Project ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
KilpAr
Yak Posting Veteran
80 Posts |
Posted - 2013-01-28 : 05:52:06
|
Ah, ok. Thanks! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-28 : 06:13:05
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|