在这段代码中,我只想要将日期和时间分开,我只想将其附加到第三个变量中,这样当我将时间变量@t
强加到datetime
时,我就编写了该代码对于日期,它需要垃圾值
你能为这个或任何其他简单方法提出任何解决方案吗?
DECLARE @d AS time
declare @s as date
declare @t as datetime
declare @l as datetime
declare @q as datetime
set @s=(SELECT CONVERT(VARCHAR(10),GETDATE(),111))
set @d='6:00PM'
set @t=cast(@s As datetime)
set @l=CAST(@d as datetime)
set @q=(SELECT DateAdd(D,0,cast(@s As datetime)+CAST(@t as datetime)))
print @q
答案 0 :(得分:0)
您需要将时间转换为日期时间并将其添加到日期:
DECLARE @t AS time
DECLARE @d AS date
DECLARE @dt as datetime
SET @t = '6:00PM'
SET @d = '14 sep 2011'
SET @dt = @d+cast(@t as datetime)
select @d,@t,@dt