hrming

[DB/SQL] CONVERT 본문

DB

[DB/SQL] CONVERT

hrming 2022. 10. 21. 11:00

CONVERT(VARCHAR, GETDATE(), 112)

 

SQL문을 보다가 CONVERT문을 처음으로 봤다.. 뭔가를 변경하겠구나 싶긴했는데 저 뒤에있는 112는 뭔지..아리송..

구글링하다가 아래 사이트에서 관련 정보를 찾았다.

 

 

The CONVERT function converts values from one data type to another.

The format of the converted data type may also be specified.

If the conversion fails, an error is returned.

 

CONVERT (data_type(length), expression, style)

  data_type -- data type the expression must be converted to.

  length -- optional, the length of the result data type.

  expression -- the value to be converted.

  style -- optional, a format to be used to the result.

 

맨 마지막에 있는 숫자 112는 Convert할 Date and Time style이었다.

112 ISO yyyymmdd

 

https://www.dofactory.com/sql/convert

 

SQL CONVERT Function - Dofactory

Earn income with your data and sql skills Sign up and we'll send you the best freelance opportunities straight to your inbox. We're building the largest self-service freelancing marketplace for people like you.

www.dofactory.com

 

 

+ 2023/01/03 실제로 사용!

SELECT CONVERT(varchar(10), B.BRTH_DT, 103),

Comments