How to convert int to date in SQL Server 2008

前端 未结 5 936
情歌与酒
情歌与酒 2020-12-09 18:50

I am using MS SQL Server 2008, and in a table I have column idate as date but in the integer format. But in the query I want that in the date format. Is it possible to conve

5条回答
  •  长情又很酷
    2020-12-09 19:33

    Reading through this helps solve a similar problem. The data is in decimal datatype - [DOB] [decimal](8, 0) NOT NULL - eg - 19700109. I want to get at the month. The solution is to combine SUBSTRING with CONVERT to VARCHAR.

        SELECT [NUM]
           ,SUBSTRING(CONVERT(VARCHAR, DOB),5,2) AS mob
        FROM [Dbname].[dbo].[Tablename] 
    

提交回复
热议问题