My SQL Azure database has a stored procedure that has the merge statement. When my database on Azure was updated to latest v12 update , this procedure started throwing following error on Merge statement
Error: Cannot bulk load. The bulk data stream was incorrectly specified as sorted or the data violates a uniqueness constraint imposed by the target table. Sort order incorrect for the following two rows: primary key of first row: (4, 2, 153, 44667), primary key of second row: (4, 2, 90, 1897).
I tried splitting the merge statement into separate update and insert statement but it still throws the same error on simple update statement.
following statement gives the same error
SET pc.Archived = 0,
pc.SortIndex = cc.SortIndex
FROM dbo.Categories pc
JOIN #ChildCategories cc ON pc.ParentCategoryID = @CategoryID and pc.CategoryTypeID = @CategoryTypeID and pc.CategoryName = cc.CategoryName
Any one any idea about what might be causing this problem and how to fix it.