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

SQL Server 中的自定義排序

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

問題描述

限時送ChatGPT賬號..

我有一個表格,其中的結(jié)果使用ORDER"列進(jìn)行排序,例如:

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

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

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

我最初的想法是設(shè)置一個標(biāo)量函數(shù),當(dāng)向表中添加新條目時,該函數(shù)可用作默認(rèn)值:

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)

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

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

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

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?

推薦答案

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

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.

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

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 對返回值進(jìn)行排序,以確保返回序列一致.

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.

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

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

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來存儲字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
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轉(zhuǎn)換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 国产精品成av人在线视午夜片 | 99视频在线免费观看 | 欧美日韩精品中文字幕 | 国产午夜亚洲精品不卡 | 中文字幕日韩欧美 | 亚洲免费精品一区 | 国产在线观看一区二区 | 91资源在线 | 午夜丰满少妇一级毛片 | 国产一区二区久久 | 天堂久久网 | 亚洲免费精品 | 欧美日韩综合一区 | 国产激情一区二区三区 | 一区二区三区四区国产精品 | 亚洲一区av在线 | 亚洲国产成人精品久久 | 亚洲理论在线观看电影 | 欧美精品三区 | 伊人久久综合 | 亚洲一区二区不卡在线观看 | 久久精品99 | 狠狠操狠狠操 | 日韩一二区 | 中文字幕成人在线 | 男人的天堂视频网站 | 国产欧美在线一区二区 | 日韩在线一区二区三区 | 亚洲性人人天天夜夜摸 | 亚洲 91| 亚洲黄色一区二区三区 | 超碰在线观看97 | 国产一区二区在线免费观看 | av网站在线免费观看 | 337p日本欧洲亚洲大胆精蜜臀 | 成人国产在线观看 | 狠狠av| 天堂在线网 | 国产精品国产成人国产三级 | 国产精品一区二区三区四区 | 亚洲激情在线观看 |