[mssql] convert yyyyMMddhhmmss string to datetime
DECLARE @stringDatetime CHAR(14) = '20160823160000' -- yyyyMMddhhmmss DECLARE @convertedDatetime DATETIME = NULL SELECT @convertedDatetime = CAST((SUBSTRING(@stringDatetime,1,4) + '-' + SUBSTRING(@stringDatetime,5,2) + '-' + SUBSTRING(@stringDatetime,7,2) + ' ' + SUBSTRING(@stringDatetime,9,2) + ':' + SUBSTRING(@stringDatetime,11,2) + ':' + SUBSTRING(@stringDatetime,13,2)) AS DATETIME) SELECT @c..
[mssql] substring 문자열 자르기
DECLARE @addressCode CHAR(10) = '1147010100' SELECT SUBSTRING(@addressCode, 1,2) AS sidoCode -- 11 , SUBSTRING(@addressCode, 3,3) AS gugunCode -- 470 , SUBSTRING(@addressCode, 6,3) AS dongCode -- 101 , SUBSTRING(@addressCode, 9,2) AS riCode -- 00 demo : http://rextester.com/DHEU53218 mssql 은 시작점이 javascript 나 기타 언어들과 다르게 1부터 시작한다. 링크 : javascript 문자열 자르기