-1

How do i connect both these tables to have data connected based on department names and week number. So that if the weeknumber don't match up, it shows nulls for others.

http://sqlfiddle.com/#!6/3bbd3/1

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Manny Balboa
  • 73
  • 2
  • 4
  • 15

1 Answers1

1

A full outer join should do the trick:

SELECT          d.id, 
                d.name, 
                f.id, 
                DATEPART(WEEK, setupdate) as WeekNumber  
FROM            departments d
FULL OUTER JOIN forecast f ON d.name = f.name AND
                DATEPART(WEEK, setupdate) = DATEPART(WEEK, forecast)
Mureinik
  • 297,002
  • 52
  • 306
  • 350