Franchesco Franchesco - 6 months ago 8
SQL Question

Convert two date columns from two diferent tables into one in sql server

I need to make a query in sql server.. I have two tables

Table#1
:

Id -- OneDate -- HoursWork
1 -- 25/04/2014 -- 5
2 -- 26/04/2014 -- 7


Table#2
:

Id -- ADate -- HoursRest
1 -- 25/04/2014 -- 5


I want a query with this result

Id -- Date -- HoursWork -- HoursRest
1 -- 25/04/2014 -- 5 -- 5
2 -- 26/04/2014 -- 7 -- 0


As you can see I need to match by id and by date, do you have an idea how to do this?

Answer
SELECT table1.id
, table1.onedate
, table1.hourswork
, ISNULL(table2.hoursrest, 0)
FROM table1 LEFT JOIN table2 ON table1.id = table2.id