MS SQL convert integer to datetime
2014-09-26 13:31
127 查看
在MSSQL建立系統日誌時,有一個Table叫做[sysjobschedules],其中欄位[next_run_date]及[next_run_time]定義為int,與一般常使用的Datetime不同,於是使用Convert轉換,語法如下。
SELECT [schedule_id] ,[job_id] ,[next_run_date] ,[next_run_time] ,case when next_run_date = 0 then null else CONVERT(DATETIME, CONVERT(NVARCHAR(4), [next_run_date] / 10000) + '-' + CONVERT(NVARCHAR(2), [next_run_date] % 10000 / 100) + '-' + CONVERT(NVARCHAR(2), [next_run_date] % 100) + ' ' + CONVERT(NVARCHAR(2), [next_run_time] / 10000) + ':' + CONVERT(NVARCHAR(2), [next_run_time] % 10000 / 100) + ':' + CONVERT(NVARCHAR(2), [next_run_time] % 100), 120) end datetime FROM [msdb].[dbo].[sysjobschedules]
相关文章推荐
- Convert Datetime to String in Sql Server
- How to convert from string to datetime in sql server? - Sealyu - BlogJava
- Convert Datetime to String in Sql Server (转)
- SQL CONVERT FUNCTION CONVERT DATETIME TO STRING
- Convert Datetime to String in Sql Server
- Convert Datetime to String in Sql Server
- Convert Datetime to String in Sql Server
- Convert Datetime to String in Sql Server (转)
- Convert Datetime to String in Sql Server
- MS SQL Server中的CONVERT日期格式化大全
- [导入]LINQ体验(11)——LINQ to SQL语句之Null语义和String/DateTime方法
- MS SQL Server中的CONVERT日期格式化大全
- MS SQL Server中的CONVERT日期格式化大全
- MS SQL Server中的CONVERT日期格式化大全
- How to monitor blocking in SQL Server 2005 and in SQL Server 2000 [ZT-MS]
- LINQ体验(11)——LINQ to SQL语句之Null语义和String/DateTime方法
- MS SQL Server中的CONVERT日期格式化大全
- MS SQL Server中的 CONVERT 日期时间 格式化大全
- 20080409 - unable to convert MySQL datetime value to System.DateTime
- MS SQL Server 中Convert转换时间的用法