方法1:
insert into select--->
insert into tbl2 select id,treeLevel from tbl2
方法2:
select into from--->
select id,treeLevel into tbl1 from tbl2
示例:
alter function dbo.tblForJson(@SuperMan varchar(50),@TreeDepth int) returns @tempSubGroup table(ID int identity(1,1),PersonName nvarchar(50),ParentID int,Treel int) as begin declare @i int --树深度 declare @tmpId int declare @curLevelInfo table(ParentID int,Person nvarchar(50)) --当前层 set @i=0 insert @tempSubGroup values(@SuperMan,0,@i) while @i<@TreeDepth-1 begin delete from @curLevelInfo insert into @curLevelInfo select ID,PersonName from @tempSubGroup where treel=@i set @i=@i+1; insert into @tempSubGroup select junior,ParentID,@i from PTS_SubGroup inner join Person on junior=Name right join @curLevelInfo on superior=Person where superior=Person and treeLevel=1 and Coding=1 end return end