[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..