I'm not sure I understand your question, but I think you are asking how to synthesize a suitable SortOrder during insertion into a table. You must use ROW_NUMBER () categorized. Of course, you will need to define a sorting criterion that gives an order of magnitude from 1 to X:
INSERT INTO myTable (SortOrder, CategoryId, <other columns> ...)
SELECT ROW_NUMBER() OVER (PARTITION BY CategoryId ORDER BY mySortCriteria)
, CategoryId
, <other columns> ...
FROM SourceTable;
source
share