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 |
ismailc
Constraint Violating Yak Guru
290 Posts |
Posted - 2013-10-02 : 09:31:20
|
Good day, i need help and i think its a real stupid questioni want a mutiple where clause:field1,field225,025,222,0SQL: where (field2 <> 0 and field1 = 25)I want to return:field1,field225,222,0but it only returns: 25,22i only want exclude the combination of (field2 <> 0 and field1 = 25)but return everything else, please assist |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-02 : 09:40:44
|
quote: Originally posted by ismailc Good day, i need help and i think its a real stupid questioni want a mutiple where clause:field1,field225,025,222,0SQL: where (field2 <> 0 and field1 = 25)I want to return:field1,field225,222,0but it only returns: 25,22i only want exclude the combination of (field2 <> 0 and field1 = 25)but return everything else, please assist
Not quite clear to me the rule that you want to use - can you give this a try? ;with cte as( select *, row_number() over (partition by field1 order by case when field2 = 0 then 0 else 1 end) as RNfrom YourTable)select field1,field2 from cte where RN = 1; |
|
|
ismailc
Constraint Violating Yak Guru
290 Posts |
Posted - 2013-10-02 : 09:44:15
|
Thank You - looks very complicatedshould be simpler methodi want to exclude the combination of field1:25 & field2:0 = (250)but return everything else |
|
|
ismailc
Constraint Violating Yak Guru
290 Posts |
Posted - 2013-10-02 : 09:49:04
|
Apologies - i was being silly where ((field2 <> 0 and field 1= 25) or (field2= 0and field1 <> 25) or (field2<> 0 and field1 <> 25))Thank You ALL |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-04 : 03:14:20
|
quote: Originally posted by ismailc Apologies - i was being silly where ((field2 <> 0 and field 1= 25) or (field2= 0and field1 <> 25) or (field2<> 0 and field1 <> 25))Thank You ALL
you just need thisWHERE CASE WHEN field1 = 25 AND field2 = 0 THEN 0 ELSE 1 END = 1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|