I have three tables #Factsource,#Fact and#DimSource
#factSource and#fact are joined on(Rx_Identifier)
#FactSource and#DimSource are joined on(Rx_Pres_No, Refill_no)
I am loading the #Fact from#factSource everyday by joining onRx_Identifier for incrementals.
But the someof the rows which are in#DimSource are notin#FactSource, those i need toinsertinto#Fact
Data islike:
Table:#FactSource
Rx_Identifier Rx_Pres_no Refill_no
100 100
101101
Table:#Fact
Rx_Identifier Rx_Pres_no Refill_no
100 100
101101
Table:#DimSource
Rx_Pres_no Refill_no
100
101
201
The third rowfromtable#Dimsource is missing in#FactSource, so i want toinsert that into#fact.
I wrote the below query and it is inserting that record into#Fact table everytime i run the query.The row is
getting duplicated in#Fact table.Whereis my query going wrong.
Query i wrote:
INSERTINTO#FACT (RX_IDENTIFIER,RX_PRES_NO,REFILL_NO)
SELECT ISNULL(SO.RX_IDENTIFIER,-1),DIM.RX_PRES_NO,DIM.REFILL_NOFROM#DIMSource DIMLEFTJOIN#FactSource SOON DIM.RX_PRES_NO = SO.RX_PRES_NOAND DIM.REFILL_NO = SO.REFILL_NOLEFTJOIN#FACT FAON SO.RX_IDENTIFIER = FA.RX_IDENTIFIERWHERE SO.RX_PRES_NO ISNULLAND SO.REFILL_NO ISNULLAND FA.RX_IDENTIFIER ISNULLAND SO.RX_IDENTIFIER ISNULL
↧
TSQL Query
↧