Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Increment a value inside stored procedure using while loop

$
0
0


Declare @a nt
        ,@b nvarchar(6)


SET @A = (SELECT MIN(A) FROM #DataToload)
while @A is not null 
begin
Set @B = (select MIN(B) FROM #DataToload)
   while @B is not null 
        begin


Select * from [XYZ].[dbo].[FactTbl]
WHERE 
A = @A and B = @B

      set @B = (select MAX(B)  from [#DataToload]  

                             where B> @B)    
        END   

    set @A = (Select MAX(A)  from [#DataToload] 
                      where A> @A)
END

Above query is generating two sets of data, one with @A and other one @B.

All I want it to pass both the variable in a loop and insert the data. Is it possible to define two variables in WHERE clause.

                               

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>