本文介绍了从pl SQL块中的select语句为多个变量赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Assign values to multiple variables from select statement in pl sql block 







Declare @count int,
		@Leadownernew int,@leadownerold int,@leadid int







select  Leadownernew,leadownerold,leadid,Id from #TempTable where Id=@count

now I want to assign  values as
set @Leadownernew =Leadownernew
set @leadownerold=leadownerold


--	 SET @Leadownernew =  (  select Leadownernew ) @leadownerold=   ( leadownerold, Id from #TempTable where Id=@count);





我尝试过:





What I have tried:

Declare @count int,
		@Leadownernew int,@leadownerold int,@leadid int
		 DECLARE @TopRelatedItemId int;
        SET @TopRelatedItemId =
        (
           SELECT max(id) RelatedItemId
           FROM #TempTable


        )
		 --print ''+@TopRelatedItemId
		-- Declare @count int;
		 set @count=1;
		 while(@count<=@TopRelatedItemId)
        begin


		select  Leadownernew,leadownerold,leadid,Id from #TempTable where Id=@count

	--	 SET @Leadownernew =  (  select Leadownernew ) @leadownerold=   ( leadownerold, Id from #TempTable where Id=@count);

       --  select  Leadownernew,leadownerold,leadid,Id from #TempTable where Id=@count
		 --where
		 -- where
		 --set @Leadownernew=Leadownernew;

		 set @count=@count+1;
        End

推荐答案

DECLARE @name varchar(10)
DECLARE @id  int;

SELECT @name = s.name,
       @id = s.id
FROM sysobjects s
WHERE s.id = (SELECT max(a.id) FROM sysobjects a)

PRINT @name
PRINT @id


这篇关于从pl SQL块中的select语句为多个变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 15:43