SQL Server: Transfer YYYYMMDD-HHMMSS to mm/dd/yyyy hh:mm:ss

后端 未结 3 1440
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 01:15

My SQL Server system is 2016.

As topic, I want to convert YYYYMMDD-HHMMSS to mm/dd/yyyy hh:mm:ss, and use dynamic SQL to fulfill this.

My da

3条回答
  •  离开以前
    2021-01-17 01:53

    Select CONVERT(VARCHAR(25) , CAST(LEFT(ID , 8) AS DATETIME), 101) 
           + ' ' +  LEFT(RIGHT(ID , 6) ,2) + ':' 
           + SUBSTRING(RIGHT(ID , 6) , 3,2) + ':' 
           + RIGHT(ID , 2) 
    FROM TableName 
    

提交回复
热议问题