I was just going to post about some nonsense I've heard an seen in my new job (and it's only my second day)
I'm changing the code, but I leave the basic idea of what made me say WTF
TRUNCATE TABLE Temp_Table
INSERT INTO Temp_Table
SELECT period_id,
1 AS country_id,
column_x,
column_y,
column_z
FROM SomeCountryDB..SomeTable
DELETE FROM Temp_Table
WHERE period_id BETWEEN @start_period AND @end_period
AND country_id = 2
INSERT INTO Temp_Table
SELECT period_id,
2 AS country_id,
column_x,
column_y,
column_z
FROM OtherCountryDB..SomeTable
DELETE FROM Temp_Table
WHERE period_id BETWEEN @start_period AND @end_period
AND country_id = 3
---And so on with 7 tables
Maybe some rows appeared out of nowhere, we'll better delete them.
And the quote that made my day:
I'm not sure if it's using a LEFT JOIN or an LEFT OUTER JOIN, I'll have to check