How to sort values in columns and update table?

前端 未结 7 2510
花落未央
花落未央 2020-12-05 15:28

I\'m completely new to sql and can\'t do that myself. So I need your help. I want to sort values in column and then save changes. But I don\'t know how to do that.

T

7条回答
  •  离开以前
    2020-12-05 15:51

    This is my fix... stupid simple:

    1. Extract to temp table

    SELECT SortKeyValue (add any other fixed values, just don't include the existing sequence) INTO #Temp FROM SourceTable;

    1. Empty the table:

    TRUNCATE TABLE SourceTable

    1. Reinsert:

    INSERT INTO SourceTable (SortKeyValue, DisplayOrder (plus other fields)) SELECT SortKeyValue, ROW_NUMBER() OVER (ORDER BY SortKeyValue) AS DispOrd (plus other fields) FROM #Temp;

    1. Done!

提交回复
热议问题