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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Prior Omint using select

Author  Topic 

wylderubicon
Starting Member

10 Posts

Posted - 2008-02-29 : 10:30:19
One more question.

I need to use select using some type of a prior omit.

for example, I have 2 selects:

select * from table abc where zip in ('07661') and name like 'A%'

go

select * from table abc where zip in ('07661') and company like 'ABC&'


there could be common records in both select statements, but I want to exclude the same records from the first select when I run my second one.

I could say

select * from table abc where zip in ('07661') and company like 'ABC&' and name not like 'A%'

in my second select, but I rather not do that, since my queries has many select criterias and its not just 2 selects.

So is there another option? a subsitution for "go"?

thanks



madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-29 : 10:33:23
select * from table abc where zip in ('07661') and name like 'A%'
except
select * from table abc where zip in ('07661') and company like 'ABC&'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

wylderubicon
Starting Member

10 Posts

Posted - 2008-02-29 : 10:47:40
this will not return the results of the first select which I need as well.
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2008-02-29 : 11:14:37
select * from
table abc
where zip in ('07661')
and (company like 'ABC&' OR name like 'A%')


-- or --

select * from table abc where zip in ('07661') and name like 'A%'
union
select * from table abc where zip in ('07661') and company like 'ABC&'

=================================================
Creating tomorrow's legacy systems today. One crisis at a time.
Go to Top of Page
   

- Advertisement -