思路:将查询到的记录保存进一个临时表,再在临时表中进行查询,用完后删除临时表;
select * from dbo.PE_Nodes
CREATE PROCEDURE [dbo].[PR_GetNodeInfoByNodeID]
@Nodeid INT
declare
@str varchar(300),
@id varchar(300),
@m int,
@n int
select * into temp from dbo.PE_Nodes where 1=0 --select * into 表A from 表B:只复制表解构,不复制数据;
set @str=SUBSTRING((select arrChildID from dbo.PE_Nodes where NodeIdentifier = (select NodeIdentifier from dbo.PE_Nodes where NodeID =Nodeid )),0,300)
set @m=CHARINDEX(',',@str)
set @n=1
WHILE @m>0
BEGIN
set @id=substring(@str,@n,@m-@n)
set @n=@m+1
set @m=CHARINDEX(',',@str,@n)
Insert into temp Select * from dbo.PE_Nodes where NodeID = @id --将查到的表数据插入到临时表;
END
select * from temp
drop table temp --删除临时表