Hi
I am posted above .. same thing again with nice formatting
;
WITH abc_cte
AS (
SELECT EmpName
,CASE
WHEN year + 1 = isnull(Lead(year, 1) OVER (PARTITION BY empname ORDER BY year), 1)
AND
year + 2 = isnull(Lead(year, 2) OVER (PARTITION BY empname ORDER BY year), 1)
THEN CASE
WHEN sal < isnull(Lead(sal, 1) OVER (PARTITION BY empname ORDER BY year), 1)
AND
isnull(Lead(sal, 1) OVER ( PARTITION BY empname ORDER BY year), 1) < isnull(Lead(sal, 2) OVER (PARTITION BY empname ORDER BY year), 1)
THEN 'yes'
ELSE 'no'
END
END AS yesno
FROM #Temp
)
SELECT empname
FROM abc_cte
WHERE yesno = 'yes'
/*
drop table #Temp
create table #Temp
(
EmpName varchar(100) null,
EmpID int null,
Sal int null,
Year int null
)
insert into #Temp select 'John',1,105,2012
insert into #Temp select 'John',1,100,2013
insert into #Temp select 'John',1,110,2014
insert into #Temp select 'John',1,120,2015
insert into #Temp select 'Sam',2,120,2013
insert into #Temp select 'Sam',2,110,2014
insert into #Temp select 'Sam',2,100,2015
insert into #Temp select 'Tim',3,120,2013
insert into #Temp select 'Tim',3,120,2014
insert into #Temp select 'Tim',3,100,2015
insert into #Temp select 'Steve',4,100,2013
insert into #Temp select 'Steve',4,150,2014
insert into #Temp select 'Steve',4,160,2015
*/