SQL Server: setting the language when creating a view

I need to have months in my language in this view. I try this:

CREATE VIEW countTask AS SET LANGUAGE Polish SELECT COUNT(*), DATENAME(Month, startdate), YEAR(startdate) FROM TBL_TASKS GROUP BY YEAR(startdate), DATENAME(Month, startdate) 

But it's not right. Do you know how I can fix this?

+5
source share
2 answers

You cannot pass the culture to DATENAME , and you cannot SET LANGUAGE in the view (as @Mike already mentioned), but if you are on SQL Server 2012 or higher, you can use FORMAT instead. Sort of

 SELECT FORMAT(GETDATE(), 'MMMM', 'pl-PL') ----------- czerwiec (1 row(s) affected) 
  • MMMM - full month name
  • MMM - short form
  • MM - month number
  • (and M is the month and day)

FORMAT https://msdn.microsoft.com/en-AU/library/hh213505.aspx

Date format strings https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx

+3
source

You cannot put set Language in a view. The look is universal. if you want to see the result from a point of view in Polish, set the language to Polish before you select it:

 SET LANGUAGE Polish SELECT * FROM countTask 
+3
source

All Articles