DECLARE @FINANCIALYEAR AS varchar(30) DECLARE @FINALFINANCIALYEAR AS int
SELECT @FINANCIALYEAR=CONVERT(VARCHAR,YEAR(GETDATE())-2) + \', \' +
CONVERT(VA
Simple query
SELECT CONVERT(VARCHAR,YEAR(GETDATE())-2) + ', ' +
CONVERT(VARCHAR,YEAR(GETDATE())-1) + ', ' +
CONVERT(VARCHAR,YEAR(GETDATE()))
SELECT DATEPART(YEAR, GETDATE()), DATEPART(YEAR, GETDATE()) - 1, DATEPART(YEAR, GETDATE()) - 2
Just check what your variable is after your SELECT:
DECLARE @FINANCIALYEAR AS varchar(30)
DECLARE @FINALFINANCIALYEAR AS int
SELECT @FINANCIALYEAR=CONVERT(VARCHAR,YEAR(GETDATE())-2) + ', ' +
CONVERT(VARCHAR,YEAR(GETDATE())-1) + ', ' +
CONVERT(VARCHAR,YEAR(GETDATE()))
SELECT @FINANCIALYEAR
The output is:
2008, 2009, 2010
This is clearly NOT a valid INT value - so it's obvious you're getting a conversion error.....
Select YEAR (GetDate())-2,YEAR (GetDate())-1, YEAR (GetDate())
this year is
Select datepart(year,getdate())
or
year(getdate())