I have this Monster SQl Query that looks to fetch data from a Staging Database, do a join on the Destination Database and insert/update data on a destination Table.
A simplified format would be somehting like this
MERGE INTO SOURCEDB.SCHEMA.DESTIANTIONTABLE AS TARGET
USING (SELECT COLA, COLB, COLC FROM STAGEDB.SCHEMA.SOURCE A INNER JOIN SOURCEDB.Schema,TABLEA) AS SOURCE
ON TARGET.ID = SOURCE.ID
WHEN MATCHED THEN UPDATE--
WHEN NOT MATCHED INSERT
Can i set the STAGING DB Name dynamically, the query is huge so i do not want to use the exec SQl syntax. Any suggestions?