Closed. This question needs details or clarity . It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post .
Closed 7 days ago.
Improve this question
I have this table in Microsoft SQL Server:
OrderDetailID (PK IDENTTIY) | OrderID (FK tblOrders) |
---|---|
1 | 1 |
2 | 1 |
3 | 1 |
4 | 2 |
5 | 2 |
Then I use the ROW_NUMBER() function to display a unique item number for each order, like this:
SELECT ROW_NUMBER() OVER (PARTITION BY OrderID ORDER BY OrderDetailID) AS ItemNo, OrderDetailID, OrderID FROM tblOrders
The output is:
ItemNo | OrderDetailID (PK IDENTTIY) | OrderID (FK tblOrders) |
---|---|---|
1 | 1 | 1 |
2 | 2 | 1 |
3 | 3 | 1 |
1 | 4 | 2 |
2 | 5 | 2 |
I want users in MS Access to be able to rearrange the ItemNo. For example, a user wants to move ItemNo 2 within OrderID 1 one place up. Meaning, this item will become ItemNo 1, and the original ItemNo 1 will become ItemNo 2.
How do I achieve this? Is it better to do on the SQL side or the front end side?
1条答案
按热度按时间moiiocjp1#
This can be done with the function RowPriority found at my repository at GitHub: VBA.RowNumbers.
Notice the demo folder with a zip containing a working demo in Access.
Full documentation in my article at Experts Exchange:
Sequential Rows in Microsoft Access