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.
Asked
Active
Viewed 531 times
1 Answers
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
-
I didn't full understand the question. But dont you need join by Id or Name too? – Juan Carlos Oropeza Nov 03 '17 at 19:03
-
@JuanCarlosOropeza you're right, good catch. I somehow skipped that requirement when reading the question. I've edited my answer accordingly. – Mureinik Nov 03 '17 at 19:07