I want to display the current month and year in a SQL query, I want it to look like this:
april/2020
I tried this:
SELECT DATENAME(MONTH,GETDATE()) + ' / ' + YEAR(GETDATE())
But, I get the following error:
Error de conversión al convertir el valor nvarchar 'Abril / ' al tipo de datos int.
How do I solve it?
It's because YEAR returns integer. You can use the same DATENAME function for the year.
It is important when you need to retrieve system values that depend on a configuration, to set the language/language for which they are required, as the same statement for two different logins can return different results.
I create a user with a default language of [us-english]
I create a user with a default language set to [Spanish]
Now running one of the queries with no language set returns different results for the two users.
The option is to set the appropriate language, regardless of the connection.
SetLanguage
YEAR
returns an integer, so you could use itCONCAT
to join the data.Example:
Demo
SQL Server cannot implicitly concatenate a string with an integer, you can do it like this:
or in the way that Luis Cazares mentions.