SQL Server CONVERT() 함수
예시
표현식을 int로 변환:
SELECT CONVERT(int, 25.65);
정의 및 사용
CONVERT() 함수는 값(모든 유형)을 지정된 데이터 유형으로 변환합니다.
팁: CAST() 함수 도 살펴보십시오 .
통사론
CONVERT(data_type(length), expression, style)
매개변수 값
Value | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data_type | 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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression | Required. The value to convert to another data type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style | Optional. The format used to convert between data types, such as a date
or string format. Can be one of the following values:
Converting datetime to character:
|
기술적 세부 사항
작동: | SQL Server(2008부터), Azure SQL Database, Azure SQL Data Warehouse, 병렬 데이터 웨어하우스 |
---|
더 많은 예
예시
표현식을 한 데이터 유형에서 다른 데이터 유형으로 변환(varchar):
SELECT CONVERT(varchar, 25.65);
예시
표현식을 한 데이터 유형에서 다른 데이터 유형으로 변환(날짜/시간):
SELECT CONVERT(datetime, '2017-08-25');
예시
표현식을 한 데이터 유형에서 다른 데이터 유형으로 변환(varchar):
SELECT CONVERT(varchar,
'2017-08-25', 101);