Khrys Khrys - 27 days ago 13
SQL Question

Output year and month with a string

Trying to output something like:

2016,11


Using this:

SELECT
CONVERT(VARCHAR(20),YEAR(GETDATE()) + ',' + MONTH(GETDATE())) AS YearMonth


Am I missing something in convert? Because I am getting this error:


Conversion failed when converting the varchar value ',' to data type
int.


Thanks

Answer

Try this.

SELECT
CONVERT(VARCHAR(20),YEAR(GETDATE())) + ',' + CONVERT(VARCHAR(20),  MONTH(GETDATE())) AS YearMonth