Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 what is wrong with this

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2011-02-16 : 04:38:59
Dc + convert(char(8), starttime, 108)

dc is a datetime field

starttime is a text field with a time in it


I want if dc is 20110215 11:00' and startime 12:00

I want it to return 20110215 12:00

what am i doing wrong?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-16 : 04:48:22
[code]dateadd(day, datediff(day, 0, Dc), 0) + starttime[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-02-16 : 04:56:27
Shorter
DECLARE	@Date DATETIME = '20110215 11:00',
@Time VARCHAR(5) = '12:00'

-- Peso
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, @Date), @Time)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2011-02-16 : 05:10:54
thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-16 : 10:36:00
quote:
Originally posted by Peso

Shorter
DECLARE	@Date DATETIME = '20110215 11:00',
@Time VARCHAR(5) = '12:00'

-- Peso
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, @Date), @Time)



N 56°04'39.26"
E 12°55'05.63"



Variable declaration with assignment will work from version 2008 onwards only

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -