Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch languages inside T-SQL table-valued function

I need to switch between languages inside body of table-valued function to return month names and weekdays in different languages. But when I try to use SET LANGUAGE RUSSIAN I get Invalid use of a side-effecting operator 'SET COMMAND' within a function. error.

Why this happens while setting variables in TVF is OK? How can I change languages inside TVFs?

like image 333
erop Avatar asked Mar 14 '23 20:03

erop


1 Answers

You can't use set language inside a function.

What version are you on?

If 2012+ you could do

SELECT FORMAT (GETDATE(), 'dddd', 'ru-RU'), 
       FORMAT (GETDATE(), 'MMMM', 'ru-RU')

instead. (Returns вторник, Сентябрь at day of answering).

On previous versions you could write a CLR function that does similar.

like image 130
Martin Smith Avatar answered Mar 18 '23 05:03

Martin Smith