Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Creating DATETIME value from integer DATE and integer TIME

Jul 5 2012 12:00AM by Madhivanan   

System table sysjobschedules from MSDB database has four columns schedule_id, job_id, next_run_date and next_run_time. The datetime value is splitted into two columns next_run_date and next_run_time in the form of integers with the format YYYYMMDD and HHMMSS respectively. This table has the informations of all the scheduled jobs

If you want to have a report that shows the jobs with next executable date in DATETIME format, you can use the following methods

Source Data

create table #sysjobschedules 
(
	schedule_id int identity(1,1), 
	job_id  uniqueidentifier default newid(), 
	next_run_date int, 
	next_run_time int
)

insert into #sysjobschedules (next_run_date,next_run_time)
select 20120618, 182326 union all
select 20120522, 71920 union all
select 20120708, 1015 union all
select 20120901, 220019 union all
select 20121211, 130659 

Method 1 : Convert date and time values and add them
select 
	next_run_date,
	next_run_time,
	next_run_date1+	stuff(stuff(next_run_time1,5,0,':'),3,0,':') as next_run_datetime
from
(
select 
	next_run_date,
	next_run_time,
	convert(datetime,cast(next_run_date as char(8)),112) as next_run_date1,
	right('00000'+cast(next_run_time as varchar(6)),6) as next_run_time1
from 
	#sysjobschedules  
) as t

Method 2 : Apply arithmetic operators to create time and add with converted date
select 
	next_run_date,
	next_run_time,
	dateadd
	(
		second,
		next_run_time/10000*3600+next_run_time/100%100*60+next_run_time%100,
		cast(cast(next_run_date as char(8)) as datetime)
	) as next_run_datetime
from
	#sysjobschedules

Method 3 : Apply arithmetic operators and make use of implicit convertion
select 
	next_run_date,
	next_run_time,
	dateadd
	(
		second,
		next_run_time/10000*3600+next_run_time/100%100*60+next_run_time%100,
		ltrim(next_run_date)
	) as next_run_datetime
from
	#sysjobschedules 

In all cases the result is
next_run_date next_run_time next_run_datetime
------------- ------------- -----------------------
20120618      182326        2012-06-18 18:23:26.000
20120522      71920         2012-05-22 07:19:20.000
20120708      1015          2012-07-08 00:10:15.000
20120901      220019        2012-09-01 22:00:19.000
20121211      130659        2012-12-11 13:06:59.000

Tags: 


Madhivanan
3 · 39% · 12472
6
 
0
Lifesaver
 
0
Refreshed
 
 
0
Incorrect



Submit

2  Comments  

  • Good technique and informative. Always fascinating to see these kind of arithmetic involving date and time values!

    commented on Jul 5 2012 1:13AM
    Ramesh Velayudhan
    765 · 0% · 40
  • Ramesh, thank you for your feedback :)

    commented on Jul 5 2012 1:17AM
    Madhivanan
    3 · 39% · 12472

Your Comment


Sign Up or Login to post a comment.

"Creating DATETIME value from integer DATE and integer TIME" rated 5 out of 5 by 6 readers
Creating DATETIME value from integer DATE and integer TIME , 5.0 out of 5 based on 6 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]