all groups > sql server programming > november 2006 >
You're in the

sql server programming

group:

query


query vanitha
11/16/2006 10:43:02 PM
sql server programming: hi,

i have a table like
orderid int
trackid int
trackevent varchar(50)

values will be like

orderid trackid trackevent
1 1 'sample'
1 2 'process'
1 3 'sample'
1 4 'process'

now i want to fetch the record where the tracking event is 'sample' and the
first occurance of the trackid where trackevent is 'process'

output shd be like this

orderid trackid trackid
1 1 2 (first subsequent occurance where
trackevent= 'process')
1 3 4


pls help me to solve this.

its very urgent.

thanks
vanitha

RE: query Krishnakumar S
11/16/2006 10:53:01 PM
Hi vanitha
Try this
SELECT
t.orderid, t.trackid,
(SELECT
TOP 1 trackid
FROM
Table1
WHERE
trackid > t.trackid AND orderid = t.orderid AND trackevent = 'process')
trackid
FROM
Table1 t
WHERE
t.trackevent = 'sample'
--
Krishnakumar S


[quoted text, click to view]
RE: query vanitha
11/16/2006 10:57:01 PM
it will give only one record for the trackingevent = 'process'

[quoted text, click to view]
RE: query vanitha
11/16/2006 11:03:01 PM
sorry sorry.

it works great.

thanks a lot.

[quoted text, click to view]
AddThis Social Bookmark Button