How to Get total working experience of an employee?
--How to Get total working experience of an employee if only Date of joining column exits in your table.
Create table emp_details(
DOJ smalldatetime -- Date of Joining
Insert into emp_details values('RAJA',convert(smalldatetime,'23/11/2002',103))
select * from emp_details
Declare @total_exp int
select @total_exp = DateDiff(year,DOJ,GETDATE()) from emp_Details where EmpName ='RAJA'
SELECT @total_Exp as total_Exp
(Note : you have to execute to all the codes exit within the ****** boundary.)
I have extended the DATEDIFF method to get exact difference in terms of months to find experience in number of years and months form.
Below is the modified code: