sql recursive select sample

declare @K int
set @K=18;

with CTE as
(
      select KullaniciID from dbo.tb_Kullanicilar
      where KullaniciID=@K
      union all
      select HE.KullaniciID from dbo.tb_Kullanicilar HE join CTE
      on HE.RaporlamaÜstAmiri=CTE.KullaniciID
)

select * from CTE where KullaniciID<>@K

--------- result
KullaniciID
10
11
12
15
16
19
20
21
22
23
24
26
27
28
29

Yorumlar