Author |
Topic |
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-13 : 11:39:29
|
Hi, I want to know how much days an employee worked until now since he employed in company.I running this :-select EMPLOYID,LASTNAME,FRSTNAME,BRTHDATE,STRTDATE,GETDATE() AS CURRENTDATE,DATEDIFF(DAY,STRTDATE,GETDATE()) AS DAYS_WORKEDfrom UPR00100WHERE INACTIVE ='0'ORDER BY STRTDATE DESCI getting in days, BUT i want in years,months,dayHow can i get. thanksRegards,SushantDBAWest Indies |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-13 : 12:11:57
|
tryselect STRTDATE, SDATE, year_worked = datediff(month, STRTDATE, SDATE) / 12, month_worked = datediff(month, STRTDATE, SDATE) % 12, days_worked = datediff(day, SDATE, getdate())from ( select STRTDATE, SDATE = case when day(getdate()) >= day(STRTDATE) then dateadd(day, day(STRTDATE) - day(getdate()), getdate()) else dateadd(month, -1, dateadd(day, day(STRTDATE) - day(getdate()), getdate())) end from UPR0100 ) s KH[spoiler]Time is always against us[/spoiler] |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-13 : 12:41:52
|
where can i put other columns, whcich i intend to see in the tableI put it EMPLOYID,LASTNAME,FRSTNAME,DEPRTMNT in the first select and it saysInvalid columns Regards,SushantDBAWest Indies |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-13 : 12:50:53
|
select STRTDATE, SDATE, year_worked = datediff(month, STRTDATE, SDATE) / 12, month_worked = datediff(month, STRTDATE, SDATE) % 12, days_worked = datediff(day, SDATE, getdate()), EMPLOYID,LASTNAME,FRSTNAME,DEPRTMNTfrom ( select STRTDATE, SDATE = case when day(getdate()) >= day(STRTDATE) then dateadd(day, day(STRTDATE) - day(getdate()), getdate()) else dateadd(month, -1, dateadd(day, day(STRTDATE) - day(getdate()), getdate())) end, EMPLOYID,LASTNAME,FRSTNAME,DEPRTMNT from UPR0100 ) s ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-13 : 13:44:09
|
thanks Visakh and KhtanRegards,SushantDBAWest Indies |
 |
|
|
|
|