从pl SQL块中的select语句为多个变量赋值 [英] Assign values to multiple variables from select statement in pl SQL block

查看:96
本文介绍了从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

推荐答案

如果我理解你的问题,你可以将作业放在 SELECT中子句。请考虑以下示例

If I understand your question correctly, you can place the assignment inside the SELECT clause. Consider the following example
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语句为多个变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆