I want to know if i'm able to do something like this, or what can be the proper query for this?
DATEDIFF ( year , , SELECT AVG (year(fechaBaja))FROM [erpVALLAS].[dbo].[sysCPEmpleados] , SELECT year(GETDATE() )
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
Yes you can, Like this:
SELECT DATEDIFF ( YEAR, (SELECT CAST(AVG(CAST(fechaBaja AS INT)) AS DATETIME) FROM [erpVALLAS].[dbo].[sysCPEmpleados]), GETDATE() ) AS [YearDiff]
But I am not sure what you would want to accomplish, more details about why and what your trying to achieve would be good.
Edit: Fixed the query
You can also set your dates in variables above to clean it up a bit. This can make it easier to understand.
DECLARE @startDate AS INT = (SELECT AVG(year(fechaBaja)) FROM [erpVALLAS].[dbo].[sysCPEmpleados]) DECLARE @endDate AS INT = (SELECT YEAR(GETDATE())) SELECT DATEDIFF ( Y, @startDate, @endDate ) AS yearDiff