도쿄사는 외노자

MSSQL에서의 CONVERT Function 사용 본문

Tech/DB・SQL

MSSQL에서의 CONVERT Function 사용

Enrai 2016. 1. 6. 09:53

출처 : http://www.w3schools.com/sql/func_convert.asp


Syntax

CONVERT(data_type(length),expression,style)


ValueDescription
data_type(length)Specifies the target data type (with an optional length)
expressionSpecifies the value to be converted
styleSpecifies the output format for the date/time (see table below)


사용예

更新日 between CONVERT(VARCHAR,DATEADD(year, -1, GetDate()),112) AND CONVERT(VARCHAR,GetDate(),112)


보통 Date형태를 Varchar로 변경하는 용도로 사용하게 되는데,

이 때 Style을 사용해 아웃풋을 조절할 수 있다.


Date의 경우

현재의 업무에서 사용하는 가장 기본적인 스타일이 12 혹은 112이다.

12 = yymmdd

112 = yyyymmdd


Time의 경우

14 or 114 = hh:mi:22:mmm (24h)

20 or 120 = yyyy-mm-dd hh:mi:ss (24h)


DATEADD의 경우는

http://www.w3schools.com/sql/func_dateadd.asp

여기를 참고하자.



'Tech > DB・SQL' 카테고리의 다른 글

How to parse comma delimited string in PL/SQL  (0) 2016.01.14
A5M2를 이용한 데이터 입력  (0) 2016.01.07
Oracle Database Link  (0) 2015.12.02
Oracle / MSSQL String-Date 형태변환  (0) 2015.07.23
DB별 TO_NUMBER  (0) 2015.07.15