SQL Query Incremental data load
I have source and staging tables & target table, I want to bring in incremental data into staging from source.
I have 2 date columnCreatedDate and UpdatedDate to work with to bring in the incremental data in stage
Table structure (ID_Pk, CreatedDate, UpdatedDate)
CreatedDate and UpdatedDate are date with time stamp and ID is PK
e.g. Created Date/updated date format ‘2024-05-09 16:13.03.5722250’
I have to write SQL to get only incremental data from source table, by using UpdateDate if not null, in case if updated date is null then use CreateDate to pull the incremental data.
I got the vmaxCreatedDate and vmaxUpdatedDate from targate table put it into varaibles and wrote below query, question is this this sql correct for incremental data load. I am inform to pick incremental data using UpdateDate in case it is NULL then use CreatedDate to bring in only incremental data
Select * from SourceTbl where updateDate > vmaxUpdatedDate and updateDate is not null
UNION
Select * from SourceTbl where createdDate > vmaxCreatedDate
I have source and staging tables & target table, I want to bring in incremental data into staging from source.I have 2 date columnCreatedDate and UpdatedDate to work with to bring in the incremental data in stageTable structure (ID_Pk, CreatedDate, UpdatedDate)CreatedDate and UpdatedDate are date with time stamp and ID is PKe.g. Created Date/updated date format ‘2024-05-09 16:13.03.5722250’I have to write SQL to get only incremental data from source table, by using UpdateDate if not null, in case if updated date is null then use CreateDate to pull the incremental data.I got the vmaxCreatedDate and vmaxUpdatedDate from targate table put it into varaibles and wrote below query, question is this this sql correct for incremental data load. I am inform to pick incremental data using UpdateDate in case it is NULL then use CreatedDate to bring in only incremental dataSelect * from SourceTbl where updateDate > vmaxUpdatedDate and updateDate is not null
UNION
Select * from SourceTbl where createdDate > vmaxCreatedDate Read More