Like the error message indicates, Azure Data Factory's native CDC support requires data to be in table format. This might be the cause of the issue.
Azure Data Factory might not support using DECLARE
statements directly in the source query. Instead, use parameterized inputs where required.
Instead of hardcoding date and time values in your SQL script, use ADF's parameterized input. This will allow ADF to dynamically manage and pass these values, reducing potential errors.
Try wrapping your CDC logic into a single SELECT statement without using variables. For instance:
SELECT *
FROM cdc.fn_cdc_get_net_changes_tblname_DM2(
sys.fn_cdc_map_time_to_lsn('smallest greater than', '2023-01-24 15:50:28.540'),
sys.fn_cdc_map_time_to_lsn('largest less than or equal', '2023-09-15 12:33:44.067'),
'all'
)
If the complexity of the query grows or if you face continuous challenges, consider wrapping this logic inside a stored procedure in your SQL database, and then call that stored procedure from ADF.