We have an ETL job, which would need to insert a row into Table X, and then retrieve the IDENTITY value for the row inserted into Table X for use in later transformations.
IDENTITY is used as a surrogate key, eg like here.
In SQL Server it is possible to use SCOPE_IDENTITY but this is not available in Azure Synapse (formerly Azure SQL Data warehouse).
Simple example
╔═══════════════╦═══════╗
║ Id (IDENTITY) ║ Value ║
╠═══════════════╬═══════╣
║ 1 ║ abc ║
║ 2 ║ def ║
╚═══════════════╩═══════╝
The job will insert value "hij".
╔═══════════════╦═══════╗
║ Id (IDENTITY) ║ Value ║
╠═══════════════╬═══════╣
║ 1 ║ abc ║
║ 2 ║ def ║
║ 3 ║ hij ║
╚═══════════════╩═══════╝
The job should know the Id value = 3.
Note: doing MAX(Id) would not work, as the IDENTITY column does not guarantee incremental values, and other inserts could go into the table in the meanwhile.
Does anyone have a suggested solution for this?