Author |
Topic |
asif372
Posting Yak Master
100 Posts |
Posted - 2013-01-27 : 03:53:49
|
I have Data like this------Date-------------------Time2012-12-21 00:00:00.000 -----23:052012-12-21 00:00:00.000 -----23:052012-12-21 00:00:00.000 -----23:072012-12-21 00:00:00.000 -----23:082012-12-22 00:00:00.000 -----01:072012-12-22 00:00:00.000 -----06:59i want data like thisDateTime2012-12-21 23:05:00.0002012-12-21 23:05:00.0002012-12-21 23:07:00.0002012-12-21 23:08:00.0002012-12-22 01:07:00.0002012-12-22 06:59:00.000how can it be possiblethanks in advance |
|
shenulal
Starting Member
11 Posts |
Posted - 2013-01-27 : 04:55:02
|
select cast(CONVERT(varchar(10),'2012-12-21 00:00:00.000',101) + ' ' + '23:05' as datetime)Just replace the values with your field nameHope this will help.regards,shenulal |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-27 : 13:54:08
|
DATEADD(minute,DATEDIFF(minute,0,[Time]),[Date])------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
shan007
Starting Member
17 Posts |
Posted - 2013-01-27 : 14:13:16
|
Simplest solution, see below:declare @date datetimedeclare @time timeselect @date='2012-12-21 00:00:00.000'select @time='23:05'select CAST(@date+@time as datetime)output:2012-12-21 23:05:00.000==============================I'm here to learn new things everyday.. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-27 : 14:20:47
|
quote: Originally posted by shan007 Simplest solution, see below:declare @date datetimedeclare @time timeselect @date='2012-12-21 00:00:00.000'select @time='23:05'select CAST(@date+@time as datetime)output:2012-12-21 23:05:00.000==============================I'm here to learn new things everyday..
will work fine so long as original fields are of date/datetime and time datatypes. If varchar the format has to be consistent and unambiguos otherwise it will break------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
shan007
Starting Member
17 Posts |
Posted - 2013-01-27 : 15:07:00
|
Yes, of course, I believe the field types used by asif is date/datetime time field. If they are varchar then he has to cast them date/time before concatenation..==============================I'm here to learn new things everyday.. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-27 : 23:53:31
|
quote: Originally posted by shan007 Yes, of course, I believe the field types used by asif is date/datetime time field. If they are varchar then he has to cast them date/time before concatenation..==============================I'm here to learn new things everyday..
Nope still missing my pointThe cast will not work fine so long as date values are inconsistent or have an ambiguos formatRead this http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|