Sunday, April 17, 2022

Get Maximum value from a ROW Data

 










-- one time table create

--CREATE TABLE InitialData (    

--    RowNum   int  IDENTITY(1,1) NOT NULL , 

-- loan  decimal (17, 2)

       

--  )    







declare @sql varchar(max);

DECLARE @paramDefinition nvarchar(500);


DECLARE @sid int = 1;



  DECLARE @RowSl INT    

     ,@Count INT    

   

 

SET @RowSl = 0    

SET @Count = 6 -- (SELECT COUNT(*) FROM Tables)    

 




WHILE @RowSl <= @Count    

BEGIN 


Set @sql = 'INSERT INTO  InitialData SELECT ';


declare @ColName varchar(28);

Set @ColName=  'loan_' + Cast( format (@RowSl, '0#')  as varchar(5)) +' ' ; 

SET @sql =  @sql + @ColName ;


SET @sql = @sql + ' FROM PRA_MN_RPT_TAB_XL_PD_Test WHERE RowNum =' + CAST( @sid AS nvarchar(2));


EXECUTE(@sql)

 

SET @RowSl += 1    

END -- End While    


SELECT MAX(loan) FROM  InitialData;

No comments:

Post a Comment

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.