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 2000 Forums
 SQL Server Development (2000)
 date combining

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2001-12-14 : 10:37:10
I have two fields a smalldatetime and a char(10).

Looks like this:

datevalue timevalue
------------------------------------------------------ ----------
2001-12-13 00:00:00 6:00
2001-12-13 00:00:00 6:30
2001-12-14 00:00:00 7:00
2001-12-14 00:00:00 7:30

How can I combine these two columns to a valid date/time in the
most efficient manner. I have taken all the parts and then combined
them with a convert but it seems clunky.

Any suggestions?


slow down to move faster...

skillile
Posting Yak Master

208 Posts

Posted - 2001-12-14 : 11:49:53
This is what I have: I do this then combine in the client app.
Just wondering if there was a more efficient way to do this

select a.oid,
b.tid,
convert(smalldatetime, b.timevalue,101) as schedtime,
b.datevalue,
datepart(yyyy,b.datevalue) as year,
datepart(mm,b.datevalue) as month,
datepart(dd,b.datevalue) as day,
datepart(hh,convert(smalldatetime, b.timevalue,101)) as hour,
datepart(mi,convert(smalldatetime, b.timevalue,101))as minute,
datepart(ss,convert(smalldatetime, b.timevalue,101))as second
from tblclavaildef a
inner join tblclavailtime b on a.cloid=b.cloid
where a.oid=@oid
AND b.datevalue=@ddate
AND b.scheduled=0
ORDER BY schedtime

slow down to move faster...
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2001-12-14 : 11:56:25
How about extracting just the date of the datevalue as varchar, concatenating the timevalue, and converting back to datetime? Not having your tables, I just tested this with getdate() and a literal, like this:

select convert(datetime,(convert(varchar(11), getdate(), 101) + ' 6:30 PM'), 101)

-------------------
It's a SQL thing...

Edited by - AjarnMark on 12/14/2001 11:56:55
Go to Top of Page
   

- Advertisement -