Skip to content
Advertisement

Inserting distinct values and calculated field from one table to another

I’m inserting values from DailyFile into Department. The intended functionality is: only DepartmentName which doesn’t currently appear in dbo.Department is to be inserted, both DepartmentName and DepartmentNameAlternative are populated with the dbo.DailyFile.DepartmentName and Increment is incremented by one. The insert statement throws the following error:

DB script:

DB Fiddle

Advertisement

Answer

Try this:

The idea is to get the new items, to get the current max increment value and then using row_number to ensure to icrements are unique.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement