How to Convert datetime value to yyyymmddhhmmss in SQL server?
Since SQL Server Version 2012 you can use:
SELECT format(getdate(),'yyyyMMddHHmmssffff')
This seems to work:
declare @d datetime
set @d = '2014-04-17 13:55:12'
select replace(convert(varchar(8), @d, 112)+convert(varchar(8), @d, 114), ':','')
Result:
20140417135512
SELECT REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(19), CONVERT(DATETIME, getdate(), 112), 126), '-', ''), 'T', ''), ':', '')