Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
This is what I have so farSELECT DATEDIFF(Year, dbo.tblDIMHREmployee.HREmpUniversityHireDate, GETDATE()) AS Expr1, dbo.tblDIMSystemOrganization.SysOrgSIDFROM dbo.tblDIMHREmployee INNER JOIN dbo.tblDIMSystemOrganization ON dbo.tblDIMHREmployee.SysOrgSID = dbo.tblDIMSystemOrganization.SysOrgSIDWHERE (dbo.tblDIMHREmployee.HREmpUniversityHireDate IS NOT NULL) AND (dbo.tblDIMHREmployee.HREmpRetireDate IS NULL)ORDER BY dbo.tblDIMHREmployee.HREmpUniversityHireDate
X002548
Not Just a Number
15586 Posts
Posted - 2005-03-17 : 11:54:08
Don't you need a GROUP BY?What class is this for?EDIT And don't worry about WHERE the Date is not null
SELECT o.SysOrgSID , AVG(DATEDIFF(dd, e.HREmpUniversityHireDate, GETDATE())/360.00) AS AVG_YearsHired FROM tblDIMHREmployee eINNER JOIN tblDIMSystemOrganization o ON e.SysOrgSID = o.SysOrgSID WHERE e.HREmpRetireDate IS NULLGROUP BY o.SysOrgSID