Лучший способ сделать это - создать функцию:
create FUNCTION [dbo].[udfGetDateTimeFromInteger]
(
@intDate int,
@intTime int
)
RETURNS datetime
AS BEGIN
-- Declare the return variable here
DECLARE @DT_datetime datetime = NULL,
@str_date varchar(11),
@str_time varchar(8)
if(@intDate is not null and @intDate > 0)
begin
select @str_date = CAST( cast(@intDate as varchar(8)) AS date)
if @intTime=0
select @str_time ='000000'
else
select @str_time = right('0'+CONVERT(varchar(11),@intTime),6)
select @str_time =
SUBSTRING(@str_time,1,2)+':'+SUBSTRING(@str_time,3,2)+':'+SUBSTRING(@str_time,5,2)
select @DT_datetime = CAST(@str_date+' '+@str_time as datetime)
end
-- Return the result of the function
RETURN @DT_datetime
END
, а затем позвоните в select как:
declare @next_run_date int, @next_run_time int
select @next_run_date = 20160307
select @next_run_time = 130949
SELECT @next_run_date inputdate,
@next_run_time inputtime,
dbo.udfGetDateTimeFromInteger(@next_run_date, @next_run_time) outputdatetime
Вывод будет таким:
inputdate inputtime outputdatetime
20160307 130949 2016-03-07 13:09:49.000