RecipeDan
asked on
Combine Two Date Fields
Hello:
I have two tables with date fields. Table1 has the date formatted like this: 2013-03-31 13:01:00. Table2 the date is formated like this 2013-03-31. How can I combine the two tables?
I have two tables with date fields. Table1 has the date formatted like this: 2013-03-31 13:01:00. Table2 the date is formated like this 2013-03-31. How can I combine the two tables?
SELECT Table1.ArrivalDateTime, Table2.MeetingDate
FROM Table1 INNER JOIN
Table2 ON (CONVERT(date, Table1.ArrivalDateTime, 101) = Table2.MeetingDate
That join is really not good, what if you have multiple arrivals and meetings on the same day.
Your result set will be invalid.
You need to create primary and foreign keys on your tables to implement the join
Your result set will be invalid.
You need to create primary and foreign keys on your tables to implement the join
select table2.arrivaldatetime, table2.meetingdate from table1 inner join table2
on cast(floor(cast(table1.arr ivaldateti me as float) ) as datetime) = table2.meetingdate
on cast(floor(cast(table1.arr
ASKER
Awkingoo your suggestion shows as 2013-02-06 00:00:00.000. I need to delete the time in order to join the tables.
Do you just want to join on dates? Whats wrong with your query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window