I am trying to execute the below query.
I am getting the same column, but for two consecutive days. The value I am inserting is day2.Value – day1.Value.
When tab2 does not contain a value (day2), the value to be inserted should just be 0 – day1.Value
The part not working is this -day1.Value when I have data for tab1 but not tab2. Instead I just get a null?
UPDATE tab2
SET Change = ISNULL(tab2.Value ,0) - ISNULL(tab1.Value ,0)
FROM Table_Name tab1
LEFT OUTER JOIN Table_Name tab2
ON tab2.COBDate = '2012-5-18'
AND tab1.FileName = tab2.FileName
AND tab1.ID = tab2.ID
AND tab1.ScenarioID = tab2.ScenarioID
WHERE tab1.COBDate = '2012-5-17'
AND tab1.FileName = 'GBP.csv'
Try using COALESCE()?