久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL Server 中的自定義排序

Custom sort in SQL Server(SQL Server 中的自定義排序)
本文介紹了SQL Server 中的自定義排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個表格,其中的結果使用ORDER"列進行排序,例如:

I have a table where the results are sorted using an "ORDER" column, eg:

Doc_Id    Doc_Value   Doc_Order
1         aaa         1
12        xxx         5
2         bbb         12
3         ccc         24

我的問題是最初設置此訂單欄時盡可能高效且可重復使用.

My issue is to initially set up this order column as efficiently and reusably as possible.

我最初的想法是設置一個標量函數,當向表中添加新條目時,該函數可用作默認值:

My initial take was to set up a scalar function that could be used as a default value when a new entry is added to the table:

ALTER FUNCTION [dbo].[Documents_Initial_Order] 
( )
RETURNS int
AS
BEGIN

RETURN (SELECT ISNULL(MAX(DOC_ORDER),0) + 1 FROM dbo.Documents)

當用戶想要置換 2 個文檔時,我可以輕松切換 2 個訂單.

When a user wants to permute 2 documents, I can then easily switch the 2 orders.

它工作得很好,但我現在有第二張桌子,我需要以同樣的方式設置,我很確定有更好的方法來做到這一點.有什么想法嗎?

It works nicely, but I now have a second table I need to set up the same way, and I am quite sure there is a nicer way to do it. Any idea?

推薦答案

聽起來您想要一個標識列,一旦它獲得初始值,您就可以覆蓋該列.一種解決方案是有兩列,一次調用InitialOrder",這是一個自動遞增標識列,然后第二列稱為 doc_order,最初設置為與 InitialOrder 字段相同的值(甚至可能作為插入觸發器或存儲過程(如果您以這種方式進行插入),但讓用戶能夠編輯該列.

It sounds like you want an identity column that you can then override once it gets it initial value. One solution would be to have two columns, once call "InitialOrder", that is an auto-increment identity column, and then a second column called doc_order that initially is set to the same value as the InitialOrder field (perhaps even as part of the insert trigger or a stored procedure if you are doing inserts that way), but give the user the ability to edit that column.

它確實需要每條記錄額外的幾個字節,但可以解決您的問題,如果它有任何價值,您將同時擁有初始文檔順序和用戶重置順序.

It does require an extra few bytes per record, but solves your problem, and if its of any value at all, you would have both the inital document order and the user-reset order available.

另外,我不確定您的 doc_order 是否需要唯一,但如果不需要,您可以按 doc_order 和 InitialOrder 對返回值進行排序,以確保返回序列一致.

Also, I am not sure if your doc_order needs to be unique or not, but if not, you can then sort return values by doc_order and InitialOrder to ensure a consistent return sequence.

這篇關于SQL Server 中的自定義排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 日韩一区二区三区精品 | 日日爱视频| 国产精品黄色 | 国产精品免费在线 | 91九色视频 | 成人做爰www免费看视频网站 | 日韩午夜精品 | 99久久99| 在线视频亚洲 | 亚洲视频在线看 | 国产精品成人国产乱一区 | 九九色综合 | 欧美a级网站 | 人人cao| 一区在线观看 | 免费观看一级特黄欧美大片 | 激情的网站 | 国产精品美女久久久久久免费 | 国产日韩欧美一区 | 久久国产精品免费 | 中文天堂在线一区 | 欧美一级在线观看 | 成人av一区二区三区 | 欧美激情 一区 | 国产电影一区 | 免费在线看黄视频 | 国产一区二区三区日韩 | 国产精品久久久久久久久久 | 一区二区三区中文字幕 | www.亚洲精品 | 欧美 日韩 国产 成人 在线 91 | 日本久久综合网 | 精品亚洲一区二区三区 | 国产91久久精品一区二区 | 黄色毛片网站在线观看 | 韩国久久 | 中文成人在线 | 久久久久久av | 成人日b视频 | 亚洲成人精品在线 | 成人av一区二区三区 |