Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server : setting language while creating 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 correct. Do you know how can I fix it?

like image 438
Koshi Avatar asked Jun 19 '16 19:06

Koshi


People also ask

How do I change the default language in SQL Server?

Using SQL Server Management StudioIn Object Explorer, right-click a server and select Properties. Click the Advanced tab. In the Default language box, choose the language in which Microsoft SQL Server should display system messages. The default language is English.

What is the syntax for creation of views in SQL Server?

Right-click the Views folder, then click New View.... In the Add Table dialog box, select the element or elements that you want to include in your new view from one of the following tabs: Tables, Views, Functions, and Synonyms. Click Add, then click Close.

How can I change database language?

Expand the Databases and select the database whose language you want to change. Right-click on the database name, click on Properties. Select the Options menu and change the Containment type to Partial from None. Change default Language to your desired language.

How do I add another language to SQL Server?

The simplest solution is to insert data in table as NVARCHAR data type, like below. Show activity on this post. @DipGirase - You should be able to mix unicode characters from any language, for example insert into MyTable(MyColumn) values (N'हैलो दुनिया english АВГДЄЅЗИѲ àèìòù') .


2 Answers

You can't pass a culture to DATENAME and you can't SET LANGUAGE in a view (as already mentioned by @Mike) but if you're on SQL Server 2012 or above you can use FORMAT instead. Something like

SELECT FORMAT(GETDATE(), 'MMMM', 'pl-PL')

-----------
czerwiec

(1 row(s) affected)
  • MMMM is full month name
  • MMM is abbreviated form
  • MM is month number
  • (and M is 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

like image 160
Liesel Avatar answered Sep 28 '22 17:09

Liesel


You can't put the set Language inside the view. The view is universal. if you want to see the output from the view in Polish, Set Language Polish before you select from it:

SET LANGUAGE Polish
SELECT * FROM countTask
like image 44
Mike Avatar answered Sep 28 '22 18:09

Mike