Click here to Skip to main content
16,022,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 16-Sep-17 1:08am

1 solution

If I understand your question correctly, you can place the assignment inside the SELECT clause. Consider the following example
SQL
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900