Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a table like shown below:Item Comp Quantity A B 1A C 2B C E 4C F 6D E F GIf someone queries for item AI would like to populate the result like shown below.A B 1A C 2B C E 4C F 6 EFI tried using CTE, but no success. Any help would be appreciated!ThanksSar Sar
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2011-10-18 : 10:02:45
how does this line comes about ?E G 4KH[spoiler]Time is always against us[/spoiler]
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2011-10-18 : 10:09:33
Recursive CTE
; with rcte as( select Item, Comp, Quantity from tbl where Item = 'A' union all select t.Item, t.Comp, t.Quantity from rcte r inner join tbl t on r.Comp = t.Item)select *from rcteorder by Item