February 16, 2022 at 2:24 pm
Dear All
As per my request I have following input table
Create table #FirstTable(
StudYear int,
StudValue varchar(20),
SGPA float
)
insert into #FirstTable values('1','Value1','5.6')
insert into #FirstTable values('2','Value2','4.5')
insert into #FirstTable values('3','Value3','3.2')
insert into #FirstTable values('4','Value4','8.5')
insert into #FirstTable values('5','Value5','6.5')
I want Out put in following table structure
Create table #OutputTable(
StudYear int,
StudValue varchar(20),
SGPA float,
PreviousYearSGPA float
)
insert into #OutputTable values('1','Value1','5.6','5.6')
insert into #OutputTable values('2','Value2','4.5','5.6')
insert into #OutputTable values('3','Value3','3.2','4.5')
insert into #OutputTable values('4','Value4','8.5','3.2')
insert into #OutputTable values('5','Value5','6.5','8.5')
select * from #OutputTable
Thank You
February 16, 2022 at 2:47 pm
This is very easy to achieve using the LAG function
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply