SQL Server date and time concatenation in a third variable
In this code I just want that date and time are separate and I just want to append that in a third variable so I write that code when I am typecast the time variable @t
in to datetime
for date it takes garbage value
Can you suggest any solution for that or any other simple way for the problem?
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(开发者_如何学GoD,0,cast(@s As datetime)+CAST(@t as datetime)))
print @q
You need to cast the time as datetime and add it to the date :
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
精彩评论