SQL Server CAST()関数
例
値をintデータ型に変換します。
SELECT CAST(25.65 AS int);
定義と使用法
CAST()関数は、(任意のタイプの)値を指定されたデータ型に変換します。
ヒント: CONVERT()関数も確認してください。
構文
CAST(expression
AS datatype(length))
パラメータ値
Value | Description |
---|---|
expression | Required. The value to convert |
datatype | Required. The datatype to convert expression to. Can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image |
(length) | Optional. The length of the resulting data type (for char, varchar, nchar, nvarchar, binary and varbinary) |
技術的な詳細
で動作します: | SQL Server(2008以降)、Azure SQLデータベース、Azure SQLデータウェアハウス、Parallel Data Warehouse |
---|
その他の例
例
値をvarcharデータ型に変換します。
SELECT CAST(25.65 AS varchar);
例
値を日時データ型に変換します。
SELECT CAST('2017-08-25' AS datetime);