开发者

SQL Server: how to set return format?

Question: The new SQL Server 2008 database returns me values formatted English (date/float).

Is there a way开发者_StackOverflow I can set the return format ?

For example temporarely switching the database language?

Or just set the language for the current query ?


BOL: Specifies the language environment for the session. The session language determines the datetime formats and system messages.

DECLARE @Today DATETIME
    SET @Today = '12/5/2007'

    SET LANGUAGE Italian
    SELECT DATENAME(month, @Today) AS 'Month Name'

    SET LANGUAGE us_english
    SELECT DATENAME(month, @Today) AS 'Month Name' 
    GO


You cannot switch the language in SQL Server for just a single statement or specify a different language for a select.

What you need to do is:

  • either convert DATETIME to string using an appropriate "style" value in your CONVERT statement (see the MSDN docs on CONVERT for details)
  • have a batch to switch to the language needed, execute your statement, and then switch back
  • don't do the switching on the SQL Server side, but in your application
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜