WITH #Jgxx(JGBM, JGMC, JGJB, CJ)
AS
(select JGBM, JGMC, JGJB, 0 as CJ from SYS_ZCJG where JGBM = @sInTjjg
union all
select B.JGBM, B.JGMC, B.JGJB, A.CJ + 1 as CJ
from #Jgxx A inner join SYS_ZCJG B on A.JGBM = B.SJJGBM
)
select *
into #tempJgxx
from #Jgxx where JGJB not in('1', '2', '3')
AS
(select JGBM, JGMC, JGJB, 0 as CJ from SYS_ZCJG where JGBM = @sInTjjg
union all
select B.JGBM, B.JGMC, B.JGJB, A.CJ + 1 as CJ
from #Jgxx A inner join SYS_ZCJG B on A.JGBM = B.SJJGBM
)
select *
into #tempJgxx
from #Jgxx where JGJB not in('1', '2', '3')