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.
| Author |
Topic |
|
avmreddy17
Posting Yak Master
180 Posts |
Posted - 2006-06-28 : 18:42:14
|
| How can I get a all the Tickets Information related to one chainIf you see TicketID = 9 This has been replaced by TicketID 1571,If you see TicketID = 12 This has been replaced three times.If I pass 1574 to a SP , I need the whole chain ( i.e 1574 , 1573 , 1572 , 12 ) . Is there a SET Based Solution for thisTicketID OldTicketID CancelReplaceStatus----------- ----------- -------------------2 NULL NULL3 NULL NULL4 NULL NULL5 NULL NULL6 NULL NULL7 NULL NULL9 NULL R1571 9 NULL10 NULL NULL11 NULL NULL12 NULL R1572 12 R1573 1572 R1574 1573 NULLThx in AdvanceVenu |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2006-06-28 : 19:04:13
|
Refer: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=67059 Nathan Skerl |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-29 : 00:25:21
|
[code]-- Declare the table for testingdeclare @table table( TicketID int, OldTicketID int, CancelReplaceStatus char(1))-- Create the sample testing datainsert into @tableselect 2, NULL, NULL union allselect 3, NULL, NULL union allselect 4, NULL, NULL union allselect 5, NULL, NULL union allselect 6, NULL, NULL union allselect 7, NULL, NULL union allselect 9, NULL, 'R' union allselect 1571, 9, NULL union allselect 10, NULL, NULL union allselect 11, NULL, NULL union allselect 12, NULL, 'R' union allselect 1572, 12, 'R' union allselect 1573, 1572, 'R' union allselect 1574, 1573, NULL-- Querydeclare @TicketID table( seq int identity(1,1), TicketID int)declare @ticket intselect @ticket = 1574insert into @TicketID (TicketID) select @ticket where @ticket is not nullwhile (@ticket is not null)begin select @ticket = OldTicketID from @table t where t.TicketID = @ticket insert into @TicketID (TicketID) select @ticket where @ticket is not nullendselect * from @TicketID order by seq/* RESULTseq TicketID ----------- ----------- 1 15742 15733 15724 12(4 row(s) affected)*/[/code] KH |
 |
|
|
|
|
|
|
|