變更預設語言
在 SQL Server 中所設定的語言,會影響字元字串如何被解讀為日期。
變更語言會自動更新日期格式。
在這個練習中,你會分析 SET LANGUAGE 指令在一些實務範例上的影響。
你需要在 English、Croatian 和 Dutch 三種語言之間做選擇,並考量它們使用以下格式:
| Language | Date format |
|---|---|
| English | mdy |
| Croatian | ymd |
| Dutch | dmy |
本練習屬於課程
SQL Server 的資料操作函式
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
DECLARE @date1 NVARCHAR(20) = '30.03.2019';
-- Set the correct language
SET LANGUAGE ___;
SELECT
@date1 AS initial_date,
-- Check that the date is valid
ISDATE(@date1) AS is_valid,
-- Select the name of the month
___ AS month_name;