SQL Server Forums
Profile | Register | 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)
 Multiple Where Condition - fields combination
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ismailc
Constraint Violating Yak Guru

South Africa
286 Posts

Posted - 10/02/2013 :  09:31:20  Show Profile  Reply with Quote
Good day, i need help and i think its a real stupid question

i want a mutiple where clause:
field1,field2
25,0
25,22
2,0

SQL: where (field2 <> 0 and field1 = 25)
I want to return:
field1,field2
25,22
2,0

but it only returns: 25,22
i only want exclude the combination of (field2 <> 0 and field1 = 25)
but return everything else, please assist


Edited by - ismailc on 10/02/2013 09:38:17

James K
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 10/02/2013 :  09:40:44  Show Profile  Reply with Quote
quote:
Originally posted by ismailc

Good day, i need help and i think its a real stupid question

i want a mutiple where clause:
field1,field2
25,0
25,22
2,0

SQL: where (field2 <> 0 and field1 = 25)
I want to return:
field1,field2
25,22
2,0

but it only returns: 25,22
i 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 RN
from YourTable
)
select field1,field2 from cte where RN = 1;
Go to Top of Page

ismailc
Constraint Violating Yak Guru

South Africa
286 Posts

Posted - 10/02/2013 :  09:44:15  Show Profile  Reply with Quote
Thank You - looks very complicated
should be simpler method
i want to exclude the combination of field1:25 & field2:0 = (250)
but return everything else
Go to Top of Page

ismailc
Constraint Violating Yak Guru

South Africa
286 Posts

Posted - 10/02/2013 :  09:49:04  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 10/04/2013 :  03:14:20  Show Profile  Reply with Quote
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 this

WHERE CASE WHEN field1 = 25 AND field2 = 0 THEN 0 ELSE 1 END = 1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000