I get the Year and Month using this Query given below
select CAST(YEAR(GETDATE()) AS VARCHAR )+'0'+CAST(MONTH(GETDATE()) AS VARCHAR)
But for this Month is printing Correctly but for 10 month its printing 010 can any one help on this.
I get the Year and Month using this Query given below
select CAST(YEAR(GETDATE()) AS VARCHAR )+'0'+CAST(MONTH(GETDATE()) AS VARCHAR)
But for this Month is printing Correctly but for 10 month its printing 010 can any one help on this.
One method to eliminate the extraneous digit is with the RIGHT function:
SELECT CAST(YEAR(GETDATE()) AS VARCHAR(4)) + RIGHT('0' + CAST(MONTH(GETDATE()) AS VARCHAR(2)), 2);