Sorting and sorting algorithms
-- Sorting problems, such as numbers 1, 2, 3, 4, 5, and 6 -- ideas: (1) if 1 is changed to 5, that is, 1 is directly changed to, 2, 3, 4, and 5, respectively, minus 1 and 6 unchanged -- (2) if 5 is changed to 3, 5 is directly changed to and 2, 3, 4 minus 1, 6 unchanged -- (3) for example: 3 to 6, then 6 is the target value, 3 is the value to be the target -- (4) implement with transactions or stored procedures -- (5) the parameters to be passed are: Table Name, target value, value to be the target, and Create proc [dbo] in the ID column. [pro_woqu] @ ID int, -- ID value @ targetValue int, -- target value @ wishtargetValue int, -- value to be the target @ tableName varchar (100) asbegin tranupdate [User] set DisplayOrder = @ targetValue where ID = @ ID; if (@ targetValue <@ wishta RgetValue) -- if 5 is changed to 3, 5 is changed to 3, 1, and 2, 3, 4 minus 1, 6 unchanged begin update [User] set DisplayOrder = DisplayOrder + 1 where DisplayOrder >=@ targetValue and DisplayOrder <@ wishtargetValue and ID! = @ ID and ParentID = 0 endif (@ targetValue> @ wishtargetValue) -- 3 to 6, then 6 is the target value, 3 is the value of beginupdate [User] set DisplayOrder = DisplayOrder-1 where DisplayOrder <= @ targetValue and DisplayOrder> @ wishtargetValue and ID! = @ ID and ParentID = 0 endif @ error <> 0 begin rollback tranreturn 0 endelse begin commit tranreturn 1end
What is the difference between the SQL sort statement desc and ASC?
DESC indicates descending order (that is, descending order)
Use ACS to sort data in ascending order (Ascending Order)
What is the difference between the SQL sort statement desc and ASC?
DESC indicates descending order (that is, descending order)
Use ACS to sort data in ascending order (Ascending Order)