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
 General SQL Server Forums
 New to SQL Server Programming
 Query help

Author  Topic 

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-06-08 : 00:58:22
Hi,

Here is the sample table

create table #temp
(
status varchar(10)
,paxId int
,sellingItemID int
)
go
insert into #temp
select ' Old', 9, 111 union all
select ' New', 9, 111 union all
select ' New', 8, 112 union all
select ' New', 10, 112 union all
select ' Old', 9, 113 union all
select ' New', 9, 113 union all
select ' Old', 9, 114 union all
select ' New', 9, 114 union all
select ' Old', 9, 115 union all
select ' New', 9, 115 union all
select ' New', 10, 115 union all
select ' Removed ',11, 114 union all
select ' Removed ',9, 116
go


select * from #temp

expectd output:

status paxId sellingItemID
Old 9 111
New 9 111
New 8 112
New 10 112
Old 9 113
New 9 113
Old 9 114
New 9 114
Old 9 115
New 9 115
New 10 115
Removed 11 114
Removed 9 116


Thanks,

--Ranjit

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2011-06-08 : 01:26:32
select * from #temp where paxId NOT IN (0,10)

or

select * from #temp where paxId IN (9,11)

it depends on the overall data set



Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-06-08 : 01:34:17
My query as below
Working Fine


select
t1.*
from #temp t1
inner join #temp t2 on t1.PaxId=t2.PaxId and t1.sellingItemID=t2.sellingItemID and t1.status<>t2.status
union
select
t1.*
from #temp t1
where status=' Removed '


--Ranjit
Go to Top of Page
   

- Advertisement -