I Have a master OLTP table A and Target table B (Built based on the source table A). The source table will get new data everymonth and i need to update the target table B using Insert (New Data) and update (modify existing) using the source data from A. So i am writing an Insert statement which should run every month which is not working..please help
Insert into TableB XX
From TableA YY
Also, please provide the code for update stattement.
The syntax is not right.
You can't define the alias for the target table mentioned in INSERT statement. On top of that you can't reference the target table (XX in your case) in SELECT clause!
I guess as suggested in the first reply, use the MERGE statement.
Or else you can also use Left join on your key column (A in this case) to check whether the row already exist in your target or not (assuming from above SQL that you are only checking for "new data" case)