CAST 和 CONVERT (Transact-SQL)CAST and CONVERT (Transact-SQL)

適用於: 是SQL Server 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

這些函式會將某種資料類型的運算式轉換成另一種資料類型。These functions convert an expression of one data type to another.

範例: 變更輸入資料類型Example: Change the input datatype

轉換Cast

SELECT 9.5 AS Original,
       CAST(9.5 AS INT) AS [int],
       CAST(9.5 AS DECIMAL(6, 4)) AS [decimal];

轉換Convert

SELECT 9.5 AS Original,
       CONVERT(INT, 9.5) AS [int],
       CONVERT(DECIMAL(6, 4), 9.5) AS [decimal];

以下為結果集:Here is the result set.

原始Original INTint Decimaldecimal
9.59.5 99 9.50009.5000

請參閱本主題稍後的範例See the examples later in this topic.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

-- CAST Syntax:  
CAST ( expression AS data_type [ ( length ) ] )  
  
-- CONVERT Syntax:  
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )  

引數Arguments

expressionexpression
任何有效的運算式Any valid expression.

data_typedata_type
目標資料類型。The target data type. 這包括 xmlbigintsql_variantThis includes xml, bigint, and sql_variant. 無法使用別名資料類型。Alias data types cannot be used.

lengthlength
指定目標資料類型長度的選擇性整數。An optional integer that specifies the length of the target data type. 預設值是 30。The default value is 30.

stylestyle
指定 CONVERT 函式如何轉譯 expression 的整數運算式。An integer expression that specifies how the CONVERT function will translate expression. 針對樣式值 NULL,會傳回 NULL。For a style value of NULL, NULL is returned. data_type 可決定範圍。data_type determines the range.

傳回類型Return types

傳回轉譯為 data_typeexpressionReturns expression, translated to data_type.

日期和時間樣式Date and Time Styles

針對日期或時間資料類型 expressionstyle 可以具有下表中所顯示的其中一個值。For a date or time data type expression, style can have one of the values shown in the following table. 其他值則當做 0 處理。Other values are processed as 0. SQL Server 2012 (11.x)SQL Server 2012 (11.x) 開始,從日期和時間類型轉換成 datetimeoffset 時,唯一支援的樣式為 0 或 1。Beginning with SQL Server 2012 (11.x)SQL Server 2012 (11.x), the only styles supported, when converting from date and time types to datetimeoffset, are 0 or 1. 所有其他轉換樣式都會傳回錯誤 9809。All other conversion styles return error 9809.

注意

SQL ServerSQL Server 利用科威特演算法來支援阿拉伯文樣式的日期格式。supports the date format, in Arabic style, with the Kuwaiti algorithm.

不含世紀 (yy) (1)Without century (yy) (1) 含世紀 (yyyy)With century (yyyy) StandardStandard 輸入/輸出 (3)Input/Output (3)
- 0100 (1,2)0 or 100 (1,2) datetime 和 smalldatetime 的預設值Default for datetime and smalldatetime mon dd yyyy hh:miAM (或 PM)mon dd yyyy hh:miAM (or PM)
11 101101 美式英文U.S. 1 = mm/dd/yy1 = mm/dd/yy
101 = mm/dd/yyyy101 = mm/dd/yyyy
22 102102 ANSIANSI 2 = yy.mm.dd2 = yy.mm.dd
102 = yyyy.mm.dd102 = yyyy.mm.dd
33 103103 英式英文/法文British/French 3 = dd/mm/yy3 = dd/mm/yy
103 = dd/mm/yyyy103 = dd/mm/yyyy
44 104104 德文German 4 = dd.mm.yy4 = dd.mm.yy
104 = dd.mm.yyyy104 = dd.mm.yyyy
55 105105 義大利文Italian 5 = dd-mm-yy5 = dd-mm-yy
105 = dd-mm-yyyy105 = dd-mm-yyyy
66 106 (1)106 (1) - 6 = dd mon yy6 = dd mon yy
106 = dd mon yyyy106 = dd mon yyyy
77 107 (1)107 (1) - 7 = Mon dd, yy7 = Mon dd, yy
107 = Mon dd, yyyy107 = Mon dd, yyyy
88 108108 - hh:mi:sshh:mi:ss
- 9109 (1,2)9 or 109 (1,2) 預設值 + 毫秒Default + milliseconds mon dd yyyy hh:mi:ss:mmmAM (或 PM)mon dd yyyy hh:mi:ss:mmmAM (or PM)
1010 110110 USAUSA 10 = mm-dd-yy10 = mm-dd-yy
110 = mm-dd-yyyy110 = mm-dd-yyyy
1111 111111 日本JAPAN 11 = yy/mm/dd11 = yy/mm/dd
111 = yyyy/mm/dd111 = yyyy/mm/dd
1212 112112 ISOISO 12 = yymmdd12 = yymmdd
112 = yyyymmdd112 = yyyymmdd
- 13113 (1,2)13 or 113 (1,2) 歐洲預設值 + 毫秒Europe default + milliseconds dd mon yyyy hh:mi:ss:mmm(24h)dd mon yyyy hh:mi:ss:mmm(24h)
1414 114114 - hh:mi:ss:mmm(24h)hh:mi:ss:mmm(24h)
- 20120 (2)20 or 120 (2) ODBC 標準ODBC canonical yyyy-mm-dd hh:mi:ss(24h)yyyy-mm-dd hh:mi:ss(24h)
- 21121 (2)21 or 121 (2) time、date、datetime2 和 datetimeoffset 的 ODBC 標準 (使用毫秒) 預設值ODBC canonical (with milliseconds) default for time, date, datetime2, and datetimeoffset yyyy-mm-dd hh:mi:ss.mmm(24h)yyyy-mm-dd hh:mi:ss.mmm(24h)
- 126 (4)126 (4) ISO8601ISO8601 yyyy-mm-ddThh:mi:ss.mmm (無空格)yyyy-mm-ddThh:mi:ss.mmm (no spaces)

注意:針對毫秒 (mmm) 值 0,不會顯示毫秒十進位小數值。Note: For a milliseconds (mmm) value of 0, the millisecond decimal fraction value will not display. 例如,'2012-11-07T18:26:20.000' 值會顯示為 '2012-11-07T18:26:20'。For example, the value '2012-11-07T18:26:20.000 displays as '2012-11-07T18:26:20'.
- 127(6, 7)127(6, 7) 具有時區 Z 的 ISO8601。ISO8601 with time zone Z. yyyy-mm-ddThh:mi:ss.mmmZ (無空格)yyyy-mm-ddThh:mi:ss.mmmZ (no spaces)

注意:針對毫秒 (mmm) 值 0,不會顯示毫秒十進位值。Note: For a milliseconds (mmm) value of 0, the millisecond decimal value will not display. 例如,'2012-11-07T18:26:20.000' 值會顯示為 '2012-11-07T18:26:20'。For example, the value '2012-11-07T18:26:20.000 will display as '2012-11-07T18:26:20'.
- 130 (1,2)130 (1,2) 回曆 (5)Hijri (5) dd mon yyyy hh:mi:ss:mmmAMdd mon yyyy hh:mi:ss:mmmAM

在此樣式中,mon 代表完整月份名稱的多 Token 回曆 Unicode 表示法。In this style, mon represents a multi-token Hijri unicode representation of the full month name. 這個值無法在 SSMS 的預設美國安裝中正確呈現。This value does not render correctly on a default US installation of SSMS.
- 131 (2)131 (2) 回曆 (5)Hijri (5) dd/mm/yyyy hh:mi:ss:mmmAMdd/mm/yyyy hh:mi:ss:mmmAM

1 這些樣式值會傳回不具決定性的結果。1 These style values return nondeterministic results. 其中包括所有 (yy) (不含世紀) 樣式和 (yyyy) (含世紀) 樣式的子集。Includes all (yy) (without century) styles and a subset of (yyyy) (with century) styles.

2 預設值 (01009109131132012021121) 一律會傳回世紀 (yyyy)。2 The default values (0 or 100, 9 or 109, 13 or 113, 20 or 120, and 21 or 121) always return the century (yyyy).

3 當轉換成 datetime 時輸入;當轉換成字元資料時輸出。3 Input when you convert to datetime; output when you convert to character data.

4 專為 XML 設計。4 Designed for XML use. 若要從 datetimesmalldatetime 轉換成字元資料,請參閱上表中的輸出格式。For conversion from datetime or smalldatetime to character data, see the previous table for the output format.

5 阿拉伯回曆是具有多種變化的日曆系統。5 Hijri is a calendar system with several variations. SQL ServerSQL Server 使用科威特演算法。uses the Kuwaiti algorithm.

重要

根據預設,SQL ServerSQL Server 會根據截止年份 2049 來解譯兩位數的年份。By default, SQL ServerSQL Server interprets two-digit years based on a cutoff year of 2049. 這表示 SQL Server 會將兩位數年份 49 解譯為 2049,而將兩位數年份 50 解譯為 1950。That means that SQL Server interprets the two-digit year 49 as 2049 and the two-digit year 50 as 1950. 許多用戶端應用程式 (包含以 Automation 物件為基礎的應用程式) 都使用截止年份 2030。Many client applications, including those based on Automation objects, use a cutoff year of 2030. SQL ServerSQL Server 提供兩位數年份截止組態選項,以變更 SQL ServerSQL Server 所使用的截止年份。provides the two digit year cutoff configuration option to change the cutoff year used by SQL ServerSQL Server. 這允許一致的日期處理。This allows for the consistent treatment of dates. 我們建議您指定四位數的年份。We recommend specifying four-digit years.

6 只有在從字元資料轉換為 datetimesmalldatetime 時才支援。6 Only supported when casting from character data to datetime or smalldatetime. 將只代表日期或只代表時間元件的字元資料轉換成 datetimesmalldatetime 資料類型時,未指定的時間元件會設定為 00:00:00.000,而未指定的日期元件則會設定為 1900-01-01。When casting character data representing only date or only time components to the datetime or smalldatetime data types, the unspecified time component is set to 00:00:00.000, and the unspecified date component is set to 1900-01-01.

7使用選擇性時區指標 Z 更輕鬆地將具有時區資訊的 XML datetime 值對應到沒有時區的 SQL ServerSQL Server datetime 值。7Use the optional time zone indicator Z to make it easier to map XML datetime values that have time zone information to SQL ServerSQL Server datetime values that have no time zone. Z 指出時區 UTC-0。Z indicates time zone UTC-0. 以 + 或 - 方向位移的 HH:MM 指出其他時區。The HH:MM offset, in the + or - direction, indicates other time zones. 例如: 2006-12-12T23:45:12-08:00>。For example: 2006-12-12T23:45:12-08:00.

smalldatetime 轉換成字元資料時,包含秒或毫秒的樣式會在這些位置顯示零。When converting smalldatetime to character data, the styles that include seconds or milliseconds show zeros in these positions. datetimesmalldatetime 值轉換時,請使用適當的 charvarchar 資料類型長度來截斷不需要的日期部分。When converting from datetime or smalldatetime values, use an appropriate char or varchar data type length to truncate unwanted date parts.

使用包含時間的樣式將字元資料轉換成 datetimeoffset 時,會將時區位移附加至結果。When converting character data to datetimeoffset, using a style that includes a time, a time zone offset is appended to the result.

float 和 real 樣式float and real styles

針對 floatreal expressionstyle 可以具有下表中所顯示的其中一個值。For a float or real expression, style can have one of the values shown in the following table. 其他值則當做 0 處理。Other values are processed as 0.

ReplTest1Value 輸出Output
0 (預設)0 (default) 最多 6 位數。A maximum of 6 digits. 在適當時機,供科學記號標記法使用。Use in scientific notation, when appropriate.
11 一律 8 位數。Always 8 digits. 一律用在科學記號標記法中。Always use in scientific notation.
22 一律 16 位數。Always 16 digits. 一律用在科學記號標記法中。Always use in scientific notation.
33 一律 17 位數。Always 17 digits. 用於不失真的轉換。Use for lossless conversion. 透過這個樣式,可保證將每個不同的 float 或 real 值轉換成相異的字元字串。With this style, every distinct float or real value is guaranteed to convert to a distinct character string.

適用對象: Azure SQL DatabaseAzure SQL Database,以及 SQL Server 2016 (13.x)SQL Server 2016 (13.x) 及更新版本。Applies to: Azure SQL DatabaseAzure SQL Database, and starting in SQL Server 2016 (13.x)SQL Server 2016 (13.x).
126、128、129126, 128, 129 基於舊版原因而納入;未來版本可能會取代這些值。Included for legacy reasons; a future release could deprecate these values.

money 和 smallmoney 樣式money and smallmoney styles

針對 moneysmallmoney expressionstyle 可以具有下表中所顯示的其中一個值。For a money or smallmoney expression, style can have one of the values shown in the following table. 其他值則當做 0 處理。Other values are processed as 0.

ReplTest1Value 輸出Output
0 (預設)0 (default) 小數點左側並不會每隔三位數加一個逗號,小數點右側則會有兩位數No commas every three digits to the left of the decimal point, and two digits to the right of the decimal point

範例4235.98。Example: 4235.98.
11 小數點左側會每隔三位數加一個逗號,小數點右側則會有兩位數Commas every three digits to the left of the decimal point, and two digits to the right of the decimal point

範例3,510.92。Example: 3,510.92.
22 小數點左側並不會每隔三位數加一個逗號,小數點右側則會有四位數No commas every three digits to the left of the decimal point, and four digits to the right of the decimal point

範例4235.9819。Example: 4235.9819.
126126 轉換成 char(n) 或 varchar(n) 時,相當於樣式 2Equivalent to style 2, when converting to char(n) or varchar(n)

xml 樣式xml styles

針對 xml expressionstyle 可以具有下表中所顯示的其中一個值。For an xml expression, style can have one of the values shown in the following table. 其他值則當做 0 處理。Other values are processed as 0.

ReplTest1Value 輸出Output
0 (預設)0 (default) 使用預設剖析行為,以捨棄無意義的空白字元,而且不允許內部 DTD 子集。Use default parsing behavior that discards insignificant white space, and does not allow for an internal DTD subset.

注意: 轉換成 資料類型時,SQL ServerSQL Server 無意義空白字元的處理方式會與 XML 1.0 不同。Note: When converting to the xml data type, SQL ServerSQL Server insignificant white space is handled differently than in XML 1.0. 如需詳細資訊,請參閱建立 XML 資料的執行個體For more information, see Create Instances of XML Data.
11 保留無意義的空格。Preserve insignificant white space. 此樣式設定會設定預設 xml:space 處理,以符合 xml:space="preserve" 的行為。This style setting sets the default xml:space handling to match the behavior of xml:space="preserve".
22 啟用有限的內部 DTD 子集處理。Enable limited internal DTD subset processing.

啟用時,伺服器可以使用內部 DTD 子集所提供的下列資訊來執行非驗證的剖析作業。If enabled, the server can use the following information that is provided in an internal DTD subset, to perform nonvalidating parse operations.

- 已套用屬性的預設值- Defaults for attributes are applied
- 已解決和展開內部實體參考- Internal entity references are resolved and expanded
- 已檢查 DTD 內容模型來確定語法正確性- The DTD content model is checked for syntactical correctness

剖析器會忽略外部 DTD 子集。The parser ignores external DTD subsets. 此外,它不會評估 XML 宣告,以查看 standalone 屬性具有 yes 還是 no 值。Also, it does not evaluate the XML declaration to see whether the standalone attribute has a yes or no value. 相反地,它會將 XML 執行個體剖析為獨立文件。Instead, it parses the XML instance as a stand-alone document.
33 保留無意義的空白字元,並啟用有限的內部 DTD 子集處理。Preserve insignificant white space, and enable limited internal DTD subset processing.

二進位樣式Binary styles

針對 binary(n)char(n)varbinary(n)varchar(n) expressionstyle 可以具有下表中所顯示的其中一個值。For a binary(n), char(n), varbinary(n), or varchar(n) expression, style can have one of the values shown in the following table. 此表中未列出的樣式值將傳回錯誤。Style values not listed in the table will return an error.

ReplTest1Value 輸出Output
0 (預設)0 (default) 將 ASCII 字元轉譯成二進位位元組,或將二進位位元組轉譯成 ASCII 字元。Translates ASCII characters to binary bytes, or binary bytes to ASCII characters. 每個字元或位元組都會以 1:1 的方式轉換。Each character or byte is converted 1:1.

針對二進位 data_type,會在結果的左側新增字元 0x。For a binary data_type, the characters 0x are added to the left of the result.
121, 2 針對二進位 data_type,運算式必須是字元運算式。For a binary data_type, the expression must be a character expression. expression 必須具有偶數個十六進位數字 (0、1、2、3、4、5、6、7、8、9、A、B、C、D、E、F、a、b、c、d、e、f)。The expression must have an even number of hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, a, b, c, d, e, f). 如果 style 設定為 1,則必須具有 0x 作為前兩個字元。If the style is set to 1, the must have 0x as the first two characters. 如果運算式包含奇數個字元,或者有任何字元無效,則會引發錯誤。If the expression contains an odd number of characters, or if any of the characters is invalid, an error is raised.

如果所轉換運算式的長度超過 data_type 的長度,結果就是自右截斷。If the length of the converted expression exceeds the length of the data_type, the result is right truncated.

大於已轉換結果的固定長度 data_type 會在結果的右側新增零。Fixed length data_types larger than the converted result have zeros added to the right of the result.

字元類型的 data_type 需要二進位運算式。A data_type of type character requires a binary expression. 每個二進位字元都會轉換成兩個十六進位字元。Each binary character is converted into two hexadecimal characters. 如果所轉換運算式的長度超過 data_type 的長度,結果就是自右截斷。If the length of the converted expression exceeds the length of the data_type, it will be right truncated.

針對固定大小字元類型 data_type,如果已轉換結果的長度小於 data_type 的長度,則會在所轉換運算式的右側新增空格,以維持偶數個十六進位數字。For a fixed size character type data_type, if the length of the converted result is less than its length of the data_type, spaces are added to the right of the converted expression, to maintain an even number of hexadecimal digits.

針對 style 1 的已轉換結果,系統會在它的左邊加入字元 0x。The characters 0x will be added to the left of the converted result for style 1.

隱含的轉換Implicit conversions

隱含轉換不需要指定 CAST 函式或 CONVERT 函式。Implicit conversions do not require specification of either the CAST function or the CONVERT function. 明確轉換需要指定 CAST 函式或 CONVERT 函式。Explicit conversions require specification of the CAST function or the CONVERT function. 下圖顯示 SQL ServerSQL Server 系統提供之資料類型所能使用的所有明確和隱含資料類型轉換。The following illustration shows all explicit and implicit data type conversions allowed for SQL ServerSQL Server system-supplied data types. 這些包含 bigintsql_variantxmlThese include bigint, and sql_variant, and xml. sql_variant 資料類型進行指派時,不可使用隱含轉換,但可以隱含轉換成 sql_variantThere is no implicit conversion on assignment from the sql_variant data type, but there is implicit conversion to sql_variant.

提示

Microsoft 下載中心可將此圖表當成 PDF 檔案下載。The Microsoft Download Center has this chart available for download as a PDF file.

資料類型轉換表Data type conversion table

當您在 datetimeoffset 與字元類型 charncharnvarcharvarchar 之間轉換時,轉換過之時區位移部分的 HH 和 MM 應該永遠是兩位數。When you convert between datetimeoffset and the character types char, nchar, nvarchar, and varchar, the converted time zone offset part should always have double digits for both HH and MM. 例如 -08:00。For example, -08:00.

注意

由於 Unicode 資料使用的位元組數目一律是偶數,因此,在 binaryvarbinary 和 Unicode 支援的資料類型之間轉換時,要特別小心。Because Unicode data always uses an even number of bytes, use caution when you convert binary or varbinary to or from Unicode supported data types. 例如,下列轉換不會傳回十六進位值 41。For example, the following conversion does not return a hexadecimal value of 41. 它會傳回十六進位值 4100:SELECT CAST(CAST(0x41 AS nvarchar) AS varbinary)It returns a hexadecimal value of 4100: SELECT CAST(CAST(0x41 AS nvarchar) AS varbinary).

大數值資料類型Large-value data types

大數值資料類型具有與小數值資料類型相同的隱含和明確轉換行為,明確地說,就是 nvarcharvarbinaryvarchar 資料類型。Large-value data types have the same implicit and explicit conversion behavior as their smaller counterparts - specifically, the nvarchar, varbinary, and varchar data types. 不過,請考慮下列指導方針:However, consider the following guidelines:

  • image 轉換成 varbinary(max) (反之亦然) 是一種隱含轉換,而 textvarchar(max) 以及 ntextnvarchar(max) 之間的轉換亦是如此。Conversion from image to varbinary(max), and vice-versa, operates as an implicit conversion, as do conversions between text and varchar(max), and ntext and nvarchar(max).
  • 從大數值資料類型 (如 varchar(max) ) 轉換成較小的對應資料類型 (如 varchar) 是隱含的轉換,但如果大數值的大小超過較小資料類型的指定長度,則會予以截斷。Conversion from large-value data types, such as varchar(max), to a smaller counterpart data type, such as varchar, is an implicit conversion, but truncation occurs if the size of the large value exceeds the specified length of the smaller data type.
  • nvarcharvarbinaryvarchar 轉換成其對應的大數值資料類型是透過隱含的方式進行。Conversion from nvarchar, varbinary, or varchar to their corresponding large-value data types happens implicitly.
  • sql_variant 資料類型轉換為大數值資料類型為明確的轉換。Conversion from the sql_variant data type to the large-value data types is an explicit conversion.
  • 大數值資料類型無法轉換成 sql_variant 資料類型。Large-value data types cannot be converted to the sql_variant data type.

如需從 xml 資料類型轉換的詳細資訊,請參閱建立 XML 資料的執行個體For more information about conversion from the xml data type, see Create Instances of XML Data.

xml 資料型別xml data type

當您將 xml 資料類型明確或隱含地轉換成字串或二進位資料類型時,xml 資料類型的內容會根據定義的一組規則進行序列化。When you explicitly or implicitly cast the xml data type to a string or binary data type, the content of the xml data type is serialized based on a defined set of rules. 如需如需這些規則的相關資訊,請參閱定義 XML 資料的序列化For information about these rules, see Define the Serialization of XML Data. 如需從其他資料類型轉換成 xml 資料類型的資訊,請參閱建立 XML 資料的執行個體For information about conversion from other data types to the xml data type, see Create Instances of XML Data.

text 和 image 資料類型text and image data types

textimage 資料類型不支援自動資料類型轉換。The text and image data types do not support automatic data type conversion. 您可以將 text 資料明確地轉換成字元資料,並將 image 資料轉換成 binaryvarbinary,但最大長度是 8000 位元組。You can explicitly convert text data to character data, and image data to binary or varbinary, but the maximum length is 8000 bytes. 如果您嘗試進行不正確的轉換 (例如,將包含字母的字元運算式轉換成 int),則 SQL ServerSQL Server 會傳回一則錯誤訊息。If you try an incorrect conversion, for example trying to convert a character expression that includes letters to an int, SQL ServerSQL Server returns an error message.

輸出定序Output Collation

如果 CAST 或 CONVERT 函式輸出字元字串,並且收到字元字串輸入,則輸出的定序和定序標籤會與輸入相同。When the CAST or CONVERT functions output a character string, and they receive a character string input, the output has the same collation and collation label as the input. 如果輸入不是字元字串,輸出會使用預設的資料庫定序及強制預設的定序標籤。If the input is not a character string, the output has the default collation of the database, and a collation label of coercible-default. 如需詳細資訊,請參閱定序優先順序 (Transact-SQL)For more information, see Collation Precedence (Transact-SQL).

若要將不同的定序指派給輸出,請將 COLLATE 子句套用至 CAST 或 CONVERT 函數結果運算式上。To assign a different collation to the output, apply the COLLATE clause to the result expression of the CAST or CONVERT function. 例如:For example:

SELECT CAST('abc' AS varchar(5)) COLLATE French_CS_AS

截斷和捨入結果Truncating and rounding results

將字元或二進位運算式 (binarycharncharnvarcharvarbinaryvarchar) 轉換成不同資料類型的運算式時,轉換作業可能會截斷輸出資料、僅局部顯示輸出資料,或傳回錯誤。When converting character or binary expressions (binary, char, nchar, nvarchar, varbinary, or varchar) to an expression of a different data type, the conversion operation could truncate the output data, only partially display the output data, or return an error. 如果結果太短無法顯示,則會發生這些情況。These cases will occur if the result is too short to display. 會截斷轉換成 binarycharncharnvarcharvarbinaryvarchar (下表中所顯示的轉換除外)。Conversions to binary, char, nchar, nvarchar, varbinary, or varchar are truncated, except for the conversions shown in the following table.

來源資料類型From data type 目標資料類型To data type 結果Result
intsmallinttinyintint, smallint, or tinyint charchar *
varcharvarchar *
ncharnchar EE
nvarcharnvarchar EE
moneysmallmoneynumericdecimalfloatrealmoney, smallmoney, numeric, decimal, float, or real charchar EE
varcharvarchar EE
ncharnchar EE
nvarcharnvarchar EE

* = 結果太短,無法顯示* = Result length too short to display

E = 因結果太短無法顯示,而傳回錯誤。E = Error returned because result length is too short to display.

SQL ServerSQL Server 保證只有往返轉換 (亦即,從原始資料類型轉換成某種資料類型之後再轉換回來) 才會各版本都產生相同的值。guarantees that only roundtrip conversions, in other words conversions that convert a data type from its original data type and back again, yield the same values from version to version. 下列範例會顯示這類往返轉換:The following example shows such a roundtrip conversion:

DECLARE @myval decimal (5, 2);  
SET @myval = 193.57;  
SELECT CAST(CAST(@myval AS varbinary(20)) AS decimal(10,5));  
-- Or, using CONVERT  
SELECT CONVERT(decimal(10,5), CONVERT(varbinary(20), @myval));  

注意

請不要嘗試建構 binary 值,然後將其轉換成數值資料類型類別的資料類型。Do not construct binary values, and then convert them to a data type of the numeric data type category. SQL ServerSQL Server 不保證在不同的 SQL ServerSQL Server 版本之間,將 decimalnumeric 資料類型轉換成 binary 的結果都會相同。does not guarantee that the result of a decimal or numeric data type conversion, to binary, will be the same between versions of SQL ServerSQL Server.

下列範例會顯示因太小而無法顯示的結果運算式。The following example shows a resulting expression that is too small to display.

USE AdventureWorks2012;  
GO  
SELECT p.FirstName, p.LastName, SUBSTRING(p.Title, 1, 25) AS Title,
    CAST(e.SickLeaveHours AS char(1)) AS [Sick Leave]  
FROM HumanResources.Employee e JOIN Person.Person p 
    ON e.BusinessEntityID = p.BusinessEntityID  
WHERE NOT e.BusinessEntityID >5;  

以下為結果集:Here is the result set.

FirstName   LastName      Title   Sick Leave
---------   ------------- ------- --------`
Ken         Sanchez       NULL   *
Terri       Duffy         NULL   *
Roberto     Tamburello    NULL   *
Rob         Walters       NULL   *
Gail        Erickson      Ms.    *
(5 row(s) affected)  

當您轉換小數位數不同的資料類型時,SQL Server 有時會傳回截斷的結果值,有時會傳回捨入的值。When you convert data types that differ in decimal places, SQL Server will sometimes return a truncated result value, and at other times it will return a rounded value. 此表格顯示這個行為。This table shows the behavior.

來源From 若要To 行為Behavior
numericnumeric numericnumeric 捨入Round
numericnumeric intint 截斷Truncate
numericnumeric moneymoney 捨入Round
moneymoney intint 捨入Round
moneymoney numericnumeric 捨入Round
floatfloat intint 截斷Truncate
floatfloat numericnumeric 捨入Round

如果您將使用科學記號標記法的 float 值轉換成 decimalnumeric,就會限制為只有 17 個有效位數的值。Conversion of float values that use scientific notation to decimal or numeric is restricted to values of precision 17 digits only. 有效位數超過 17 的任何值都會捨入為零。Any value with precision higher than 17 rounds to zero.
floatfloat datetimedatetime 捨入Round
datetimedatetime intint 捨入Round

例如,10.6496 和-10.6496 這兩個值可能會被截斷,或在轉換成 intnumeric 類型期間被捨入:For example, the values 10.6496 and -10.6496 may be truncated or rounded during conversion to int or numeric types:

SELECT  CAST(10.6496 AS int) as trunc1,
         CAST(-10.6496 AS int) as trunc2,
         CAST(10.6496 AS numeric) as round1,
         CAST(-10.6496 AS numeric) as round2;

下表將顯示該查詢的結果:Results of the query are shown in the following table:

trunc1trunc1 trunc2trunc2 round1round1 round2round2
1010 -10-10 1111 -11-11

轉換目標資料類型的小數位數小於來源資料類型的資料類型時,會將值捨入。When converting data types where the target data type has fewer decimal places than the source data type, the value is rounded. 例如,這項轉換會傳回 $10.3497For example, this conversion returns $10.3497:

SELECT CAST(10.3496847 AS money);

將非數值 charncharnvarcharvarchar 資料轉換成 decimalfloatintnumeric 時,SQL ServerSQL Server 會傳回錯誤訊息。SQL ServerSQL Server returns an error message when converting nonnumeric char, nchar, nvarchar, or varchar data to decimal, float, int, numeric. 當空字串 (" ") 被轉換為 numericdecimal 時,SQL ServerSQL Server 也會傳回錯誤。SQL ServerSQL Server also returns an error when an empty string (" ") is converted to numeric or decimal.

某些日期時間轉換不具決定性Certain datetime conversions are nondeterministic

下表列出字串對日期時間轉換不具決定性的樣式。The following table lists the styles for which the string-to-datetime conversion is nondeterministic.

100 以下的所有樣式1All styles below 1001 106106
107107 109109
113113 130130

1 樣式 20 和 21 除外1 With the exception of styles 20 and 21

如需詳細資訊,請參閱將常值日期字串轉換成 DATE 值的非決定性轉換For more information, see Nondeterministic conversion of literal date strings into DATE values.

補充字元 (代理字組)Supplementary characters (surrogate pairs)

SQL Server 2012 (11.x)SQL Server 2012 (11.x) 開始,使用補充字元 (SC) 定序時,從 ncharnvarchar 到較小長度之 ncharnvarchar 類型的 CAST 作業將不會在代理字組內截斷。Starting with SQL Server 2012 (11.x)SQL Server 2012 (11.x), when using supplementary character (SC) collations, a CAST operation from nchar or nvarchar to an nchar or nvarchar type of smaller length will not truncate inside a surrogate pair. 相反地,作業會在補充字元之前截斷。Instead, the operation truncates before the supplementary character. 例如,下列程式碼片段會讓 @x 只保留 'ab'For example, the following code fragment leaves @x holding just 'ab'. 空間不足,無法保留補充字元。There is not enough space to hold the supplementary character.

DECLARE @x NVARCHAR(10) = 'ab' + NCHAR(0x10000);  
SELECT CAST (@x AS NVARCHAR(3));  

使用 SC 定序時,CONVERT 的行為類似 CAST 的行為。When using SC collations, the behavior of CONVERT, is analogous to that of CAST.

相容性支援Compatibility support

在舊版 SQL ServerSQL Server 中,timedatetime2 資料類型上之 CAST 和 CONVERT 作業的預設樣式為 121,但任一類型用於計算資料行運算式時除外。In earlier versions of SQL ServerSQL Server, the default style for CAST and CONVERT operations on time and datetime2 data types is 121, except when either type is used in a computed column expression. 若為計算資料行,預設樣式為 0。For computed columns, the default style is 0. 當您建立計算資料行、將它們用於包含自動參數化的查詢或用於條件約束定義時,這種行為就會影響計算資料行。This behavior impacts computed columns when they are created, used in queries involving auto-parameterization, or used in constraint definitions.

在相容性層級高於及等於 110 的情況下,timedatetime2 資料類型上的 CAST 和 CONVERT 作業一律具有 121 作為預設樣式。Under compatibility level 110 and higher, the CAST and CONVERT operations on the time and datetime2 datatypes always have 121 as the default style. 如果查詢仰賴舊的行為,則請使用低於 110 的相容性層級,或在受影響的查詢中明確指定 0 樣式。If a query relies on the old behavior, use a compatibility level less than 110, or explicitly specify the 0 style in the affected query.

將資料庫升級為相容性層級高於及等於 110 並不會變更已經儲存至磁碟的使用者資料。Upgrading the database to compatibility level 110 and higher will not change user data that has been stored to disk. 您必須依適當情況手動更正這項資料。You must manually correct this data as appropriate. 例如,如果您已使用 SELECT INTO,根據包含上述計算資料行運算式的來源建立資料表,則系統會儲存資料 (使用樣式 0) 而非計算資料行定義本身。For example, if you used SELECT INTO to create a table from a source containing a computed column expression described above, the data (using style 0) would be stored rather than the computed column definition itself. 您必須手動更新這項資料,以符合樣式 121。You must manually update this data to match style 121.

範例Examples

A.A. 使用 CAST 和 CONVERTUsing both CAST and CONVERT

這些範例會擷取定價第一位數是 3 的產品名稱,而且會將它們的 ListPrice 轉換成 intThese examples retrieve the name of the product, for those products that have a 3 as the first digit of list price, and converts their ListPrice values to int.

-- Use CAST  
USE AdventureWorks2012;  
GO  
SELECT SUBSTRING(Name, 1, 30) AS ProductName, ListPrice  
FROM Production.Product  
WHERE CAST(ListPrice AS int) LIKE '3%';  
GO  
  
-- Use CONVERT.  
USE AdventureWorks2012;  
GO  
SELECT SUBSTRING(Name, 1, 30) AS ProductName, ListPrice  
FROM Production.Product  
WHERE CONVERT(int, ListPrice) LIKE '3%';  
GO  

B.B. 搭配算術運算子來使用 CASTUsing CAST with arithmetic operators

此範例會將年度目前的總銷售額 (SalesYTD) 除以佣金百分比 (CommissionPCT) 來計算單一資料行 (Computed)。This example calculates a single column computation (Computed) by dividing the total year-to-date sales (SalesYTD) by the commission percentage (CommissionPCT). 此值會四捨五入為最接近的整數,接著轉換 (CAST) 成 int 資料類型。This value is rounded to the nearest whole number and is then CAST to an int data type.

USE AdventureWorks2012;  
GO  
SELECT CAST(ROUND(SalesYTD/CommissionPCT, 0) AS int) AS Computed  
FROM Sales.SalesPerson   
WHERE CommissionPCT != 0;  
GO  

以下為結果集:Here is the result set.

Computed
------
379753754
346698349
257144242
176493899
281101272
0  
301872549
212623750
298948202
250784119
239246890
101664220
124511336
97688107
(14 row(s) affected)  

C.C. 利用 CAST 來串連Using CAST to concatenate

此範例會使用 CAST 來串連非字元運算式。This example concatenates noncharacter expressions by using CAST. 它會使用 AdventureWorksDW 資料庫。It uses the AdventureWorksDW database.

SELECT 'The list price is ' + CAST(ListPrice AS varchar(12)) AS ListPrice  
FROM dbo.DimProduct  
WHERE ListPrice BETWEEN 350.00 AND 400.00;  

以下為結果集:Here is the result set.

ListPrice
------------------------
The list price is 357.06
The list price is 364.09
The list price is 364.09
The list price is 364.09
The list price is 364.09  

D.D. 利用 CAST 來產生其他可讀取的文字Using CAST to produce more readable text

此範例會使用 SELECT 清單中的 CAST,將 Name 資料行轉換成 char(10) 資料行。This example uses CAST in the SELECT list, to convert the Name column to a char(10) column. 它會使用 AdventureWorksDW 資料庫。It uses the AdventureWorksDW database.

SELECT DISTINCT CAST(EnglishProductName AS char(10)) AS Name, ListPrice  
FROM dbo.DimProduct  
WHERE EnglishProductName LIKE 'Long-Sleeve Logo Jersey, M';  

以下為結果集:Here is the result set.

Name        ListPrice
----------  ---------
Long-Sleev  31.2437
Long-Sleev  32.4935
Long-Sleev  49.99  

E.E. 搭配 LIKE 子句使用 CASTUsing CAST with the LIKE clause

此範例會先將 money 資料行 SalesYTD 值轉換成資料類型 int,接著轉換成資料類別 char(20),讓 LIKE 子句可以使用它。This example converts the money column SalesYTD values to data type int, and then to data typechar(20), so that the LIKE clause can use it.

USE AdventureWorks2012;  
GO  
SELECT p.FirstName, p.LastName, s.SalesYTD, s.BusinessEntityID  
FROM Person.Person AS p   
JOIN Sales.SalesPerson AS s   
    ON p.BusinessEntityID = s.BusinessEntityID  
WHERE CAST(CAST(s.SalesYTD AS int) AS char(20)) LIKE '2%';  
GO  

以下為結果集:Here is the result set.

FirstName        LastName            SalesYTD         BusinessEntityID
---------------- ------------------- ---------------- -------------
Tsvi             Reiter              2811012.7151      279
Syed             Abbas               219088.8836       288
Rachel           Valdez              2241204.0424      289
(3 row(s) affected)  

F.F. 搭配具類型的 XML 來使用 CONVERT 或 CASTUsing CONVERT or CAST with typed XML

這些範例示範如何使用 XML 資料類型和資料行 (SQL Server),利用 CONVERT 將資料轉換成 XML 類型。These examples show use of CONVERT to convert data to typed XML, by using the XML Data Type and Columns (SQL Server).

此範例會將含有空白字元、文字和標記的字串轉換成 XML 類型,而且會移除所有無意義的空白字元 (節點之間的界限空白字元):This example converts a string with white space, text and markup into typed XML, and removes all insignificant white space (boundary white space between nodes):

SELECT CONVERT(XML, '<root><child/></root>')  

這個範例會將含有空格、文字和標記的類似字串轉換成 XML 類型,且會保留所有無意義的空格 (節點之間的界限空格):This example converts a similar string with white space, text and markup into typed XML and preserves insignificant white space (boundary white space between nodes):

SELECT CONVERT(XML, '<root>          <child/>         </root>', 1)  

這個範例會將含有空格、文字和標記的字串轉換成 XML 類型:This example casts a string with white space, text, and markup into typed XML:

SELECT CAST('<Name><FName>Carol</FName><LName>Elliot</LName></Name>'  AS XML)  

如需其他範例,請參閱建立 XML 資料的執行個體See Create Instances of XML Data for more examples.

G.G. 搭配 datetime 資料使用 CAST 和 CONVERTUsing CAST and CONVERT with datetime data

從 GETDATE() 值開始,此範例會顯示目前的日期和時間、使用 CAST 將目前的日期和時間變更成字元資料類型,然後使用 CONVERTISO 8601 格式顯示日期和時間。Starting with GETDATE() values, this example displays the current date and time, uses CAST to change the current date and time to a character data type, and then uses CONVERT to display the date and time in the ISO 8601 format.

SELECT   
   GETDATE() AS UnconvertedDateTime,  
   CAST(GETDATE() AS nvarchar(30)) AS UsingCast,  
   CONVERT(nvarchar(30), GETDATE(), 126) AS UsingConvertTo_ISO8601  ;  
GO  

以下為結果集:Here is the result set.

UnconvertedDateTime     UsingCast              UsingConvertTo_ISO8601
----------------------- ---------------------- ------------------------------
2006-04-18 09:58:04.570 Apr 18 2006  9:58AM    2006-04-18T09:58:04.570
(1 row(s) affected)  

此範例幾乎是上一個範例的相反操作。This example is approximately the opposite of the previous example. 此範例會將日期和時間顯示成字元資料,並使用 CAST 將字元資料變更成 datetime 資料類型,然後使用 CONVERT 將字元資料變更成 datetime 資料類型。This example displays a date and time as character data, uses CAST to change the character data to the datetime data type, and then uses CONVERT to change the character data to the datetime data type.

SELECT   
   '2006-04-25T15:50:59.997' AS UnconvertedText,  
   CAST('2006-04-25T15:50:59.997' AS datetime) AS UsingCast,  
   CONVERT(datetime, '2006-04-25T15:50:59.997', 126) AS UsingConvertFrom_ISO8601 ;  
GO  

以下為結果集:Here is the result set.

UnconvertedText         UsingCast               UsingConvertFrom_ISO8601
----------------------- ----------------------- ------------------------
2006-04-25T15:50:59.997 2006-04-25 15:50:59.997 2006-04-25 15:50:59.997
(1 row(s) affected)  

H.H. 搭配二進位和字元資料使用 CONVERTUsing CONVERT with binary and character data

這些範例示範如何使用不同的樣式轉換二進位和字元資料的結果。These examples show the results of binary and character data conversion, using different styles.

--Convert the binary value 0x4E616d65 to a character value.  
SELECT CONVERT(char(8), 0x4E616d65, 0) AS [Style 0, binary to character];  

以下為結果集:Here is the result set.

Style 0, binary to character
----------------------------
Name  
(1 row(s) affected)  

此範例示範樣式 1 可以強制截斷結果。This example shows that Style 1 can force result truncation. 結果集中的字元 0 x 會強制截斷。The characters 0x in the result set force the truncation.

SELECT CONVERT(char(8), 0x4E616d65, 1) AS [Style 1, binary to character];  

以下為結果集:Here is the result set.

Style 1, binary to character
------------------------------
0x4E616D
(1 row(s) affected)  

此範例示範樣式 2 不會截斷結果,因為結果未包含字元 0x。This example shows that Style 2 does not truncate the result, because the result does not include the characters 0x.

SELECT CONVERT(char(8), 0x4E616d65, 2) AS [Style 2, binary to character];  

以下為結果集:Here is the result set.

Style 2, binary to character
------------------------------
4E616D65
(1 row(s) affected)  

將字元值 'Name' 轉換成二進位值。Convert the character value 'Name' to a binary value.

SELECT CONVERT(binary(8), 'Name', 0) AS [Style 0, character to binary];  

以下為結果集:Here is the result set.

Style 0, character to binary
----------------------------
0x4E616D6500000000
(1 row(s) affected)  
SELECT CONVERT(binary(4), '0x4E616D65', 1) AS [Style 1, character to binary];  

以下為結果集:Here is the result set.

Style 1, character to binary
---------------------------- 
0x4E616D65
(1 row(s) affected)  
SELECT CONVERT(binary(4), '4E616D65', 2) AS [Style 2, character to binary];  

以下為結果集:Here is the result set.

Style 2, character to binary  
----------------------------------  
0x4E616D65
(1 row(s) affected)  

I.I. 轉換 date 和 time 資料類型Converting date and time data types

此範例示範 date、time 和 datetime 資料類型的轉換。This example shows the conversion of date, time, and datetime data types.

DECLARE @d1 date, @t1 time, @dt1 datetime;  
SET @d1 = GETDATE();  
SET @t1 = GETDATE();  
SET @dt1 = GETDATE();  
SET @d1 = GETDATE();  
-- When converting date to datetime the minutes portion becomes zero.  
SELECT @d1 AS [date], CAST (@d1 AS datetime) AS [date as datetime];  
-- When converting time to datetime the date portion becomes zero   
-- which converts to January 1, 1900.  
SELECT @t1 AS [time], CAST (@t1 AS datetime) AS [time as datetime];  
-- When converting datetime to date or time non-applicable portion is dropped.  
SELECT @dt1 AS [datetime], CAST (@dt1 AS date) AS [datetime as date], 
   CAST (@dt1 AS time) AS [datetime as time];  

範例:Azure SQL 資料倉儲Azure SQL Data Warehouse平行處理資料倉儲Parallel Data WarehouseExamples: Azure SQL 資料倉儲Azure SQL Data Warehouse and 平行處理資料倉儲Parallel Data Warehouse

J.J. 使用 CAST 和 CONVERTUsing CAST and CONVERT

此範例會擷取定價第一位數是 3 的產品名稱,而且會將這些產品的 ListPrice 轉換成 int。它會使用 AdventureWorksDW 資料庫。This example retrieves the name of the product for those products that have a 3 in the first digit of their list price, and converts the ListPrice of these products to int. It uses the AdventureWorksDW database.

SELECT EnglishProductName AS ProductName, ListPrice  
FROM dbo.DimProduct  
WHERE CAST(ListPrice AS int) LIKE '3%';  

此範例會示範相同的查詢,但使用的是 CONVERT 而非 CAST。This example shows the same query, using CONVERT instead of CAST. 它會使用 AdventureWorksDW 資料庫。It uses the AdventureWorksDW database.

SELECT EnglishProductName AS ProductName, ListPrice  
FROM dbo.DimProduct  
WHERE CONVERT(int, ListPrice) LIKE '3%';  

K.K. 搭配算術運算子來使用 CASTUsing CAST with arithmetic operators

此範例會將產品單價 (UnitPrice) 除以折扣百分比 (UnitPriceDiscountPct) 來計算單一資料行值。This example calculates a single column value by dividing the product unit price (UnitPrice) by the discount percentage (UnitPriceDiscountPct). 此結果接著會四捨五入為最接近的整數,最後轉換 (CAST) 成 int 資料類型。This result is then rounded to the nearest whole number, and finally converted to an int data type. 此範例會使用 AdventureWorksDW 資料庫。This example uses the AdventureWorksDW database.

SELECT ProductKey, UnitPrice,UnitPriceDiscountPct,  
       CAST(ROUND (UnitPrice*UnitPriceDiscountPct,0) AS int) AS DiscountPrice  
FROM dbo.FactResellerSales  
WHERE SalesOrderNumber = 'SO47355'   
      AND UnitPriceDiscountPct > .02;  

以下為結果集:Here is the result set.

ProductKey  UnitPrice  UnitPriceDiscountPct  DiscountPrice
----------  ---------  --------------------  -------------
323         430.6445   0.05                  22
213         18.5043    0.05                  1
456         37.4950    0.10                  4
456         37.4950    0.10                  4
216         18.5043    0.05                  1  

L.L. 搭配 LIKE 子句使用 CASTUsing CAST with the LIKE clause

此範例會先將 money 資料行 ListPrice 轉換成 int 類型,接著轉換成 char(20) 類型,讓 LIKE 子句可以使用它。This example converts the money column ListPrice to an int type, and then to a char(20) type, so that the LIKE clause can use it. 此範例會使用 AdventureWorksDW 資料庫。This example uses the AdventureWorksDW database.

SELECT EnglishProductName AS Name, ListPrice  
FROM dbo.DimProduct  
WHERE CAST(CAST(ListPrice AS int) AS char(20)) LIKE '2%';  

M.M. 搭配 datetime 資料使用 CAST 和 CONVERTUsing CAST and CONVERT with datetime data

此範例會顯示目前的日期和時間,並使用 CAST 將目前的日期和時間變更成字元資料類型,最後使用 CONVERT 以 ISO 8601 格式顯示日期和時間。This example displays the current date and time, uses CAST to change the current date and time to a character data type, and finally uses CONVERT display the date and time in the ISO 8601 format. 此範例會使用 AdventureWorksDW 資料庫。This example uses the AdventureWorksDW database.

SELECT TOP(1)  
   SYSDATETIME() AS UnconvertedDateTime,  
   CAST(SYSDATETIME() AS nvarchar(30)) AS UsingCast,  
   CONVERT(nvarchar(30), SYSDATETIME(), 126) AS UsingConvertTo_ISO8601  
FROM dbo.DimCustomer;  

以下為結果集:Here is the result set.

UnconvertedDateTime     UsingCast                     UsingConvertTo_ISO8601  
---------------------   ---------------------------   ---------------------------  
07/20/2010 1:44:31 PM   2010-07-20 13:44:31.5879025   2010-07-20T13:44:31.5879025  

此範例是上一個範例的相反操作。This example is the rough opposite of the previous example. 此範例會將日期和時間顯示為字元資料,並使用 CAST 將字元資料變更成 datetime 資料類型,然後使用 CONVERT 將字元資料變更成 datetime 資料類型。This example displays a date and time as character data, uses CAST to change the character data to the datetime data type, and then uses CONVERT to change the character data to the datetime data type. 此範例會使用 AdventureWorksDW 資料庫。This example uses the AdventureWorksDW database.

SELECT TOP(1)   
   '2010-07-25T13:50:38.544' AS UnconvertedText,  
CAST('2010-07-25T13:50:38.544' AS datetime) AS UsingCast,  
   CONVERT(datetime, '2010-07-25T13:50:38.544', 126) AS UsingConvertFrom_ISO8601  
FROM dbo.DimCustomer;  

以下為結果集:Here is the result set.

UnconvertedText         UsingCast               UsingConvertFrom_ISO8601
----------------------- ----------------------- ------------------------
2010-07-25T13:50:38.544 07/25/2010 1:50:38 PM   07/25/2010 1:50:38 PM  

另請參閱See also

資料類型轉換 (資料庫引擎)Data Type Conversion (Database Engine)
FORMAT (Transact-SQL)FORMAT (Transact-SQL)
STR (Transact-SQL)STR (Transact-SQL)
SELECT (Transact-SQL)SELECT (Transact-SQL)
系統函數 (Transact-SQL)System Functions (Transact-SQL)
撰寫國際通用的 Transact-SQL 陳述式Write International Transact-SQL Statements