Hi,
Example: Employee Number 'A-001' Join on '01-07-2012' then the O/P will be showing in below.
As Employee Number 'A-001' there is no promotion in 2012 & 2013 then in Last_Designation,Promoted_Designation, Last_Gross and Promoted_Gross need to be same as 2014 or previous one. in 2012 & 2013
Below is my SQL Query with Data.
CREATE
TABLE
[dbo].[Employee](
[Emp_No] [
numeric
](18, 0)
NULL
,
[Emp_Number] [nvarchar](50)
[Emp_Name] [nvarchar](50)
[Emp_JoiningDate] [
date
]
[Emp_ResignDate] [
[Emp_Status] [nvarchar](50)
[Emp_CurrentDesignation] [nvarchar](50)
[Emp_CurrentGross] [
)
ON
[
PRIMARY
GO
INSERT
INTO
[UserDB].[dbo].[Employee]
([Emp_No]
,[Emp_Number]
,[Emp_Name]
,[Emp_JoiningDate]
,[Emp_ResignDate]
,[Emp_Status]
,[Emp_CurrentDesignation]
,[Emp_CurrentGross])
VALUES
(1,
'A-001'
'Alex'
'2012-07-01'
null
'On Board'
'Trainee3'
,2000)
(2,
'A-002'
'Smith'
'2014-07-01'
'2015-07-01'
'Resigned'
'HR1'
,1500)
[dbo].[Promotion](
[Prom_No] [
[Prom_EmpNo] [
[Last_Designation] [nvarchar](500)
[Promoted_Designation] [nvarchar](500)
[WEF_Date] [
[Promoted_Gross] [
[Last_Gross] [
[UserDB].[dbo].[Promotion]
([Prom_No]
,[Prom_EmpNo]
,[Last_Designation]
,[Promoted_Designation]
,[WEF_Date]
,[Promoted_Gross]
,[Last_Gross])
(1,1,
'Trainee1'
'Trainee2'
'2014-11-01'
,1000,500)
(2,1,
'2015-03-01'
,2000,1000)
Attachment: output.zip