I have an issue with a merge statement into a FACT TABLE
It was pretty simple until the users started to delete records from the source.
Current SQL:
Set Count = 1
WHEN NOT MATCHED
INSERT
WHEN MATCHED
UPDATED
New SQL:
So in this example, a record has been deleted from the source, it no longer matches but there is nothing to insert. I would like it the count to be set to 0.
WHEN DELETED FROM SOURCE
Set Count = 0
.
Source
Bob Jones | 1111
Mary Jones | 1112
James Jones | 1113
Helen Jones | 1114
TARGET
Bob Jones | 1111 | Count 1
Mary Jones | 1112| Count 1
James Jones | 1113| Count 1
Helen Jones | | 1114| Count 1
Peter Market | 1115| Count 0
I’m loading to a fact table using a merge and now they are just blanket deleting records, my facts are off. This must be accounted for somehow?
Thank you for any help at all.