March 24, 2011 at 6:25 am
Wonder if anyone can help me with this problem, Not getting the expected results.
CREATE TABLE #temp
(
[state] varchar(25),
[county] varchar(25)
)
Insert into #temp
([state], [county])
values
('nevada','clark'),
('missouri','clark'),
('california','clark'),
('nevada','las Vegas')
select * from #temp
where ( [state] <> 'nevada' AND [county] <> 'clark')
I would expect to get 3 records back, instead no results return.
state county
------ --------
missouri clark
california clark
nevada las vegas
What am I doing wrong?
March 24, 2011 at 6:56 am
Why would you expect 3 results? All of your rows are either in the state of Nevada, or the county of clark. Do you mean to exclude rows where either of these conditions is true, rather than both of them? If so, you need to use OR:
select * from #temp
where ( [state] <> 'nevada' OR [county] <> 'clark')
Or, you could look at it another way and say I want to return everything except where the state='nevada' AND the county = clark, in which case you could use:
select * from #temp
where NOT ( [state] = 'nevada' AND [county] = 'clark')
March 24, 2011 at 7:28 am
2nd Statement works we will use that one Thanks for your input. 😎
March 24, 2011 at 7:37 am
That worked and gave me the expected results. Thank you very much!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply