2011-05-05 55 views
2

我正在製作應用程序,會員可以選擇DVD並將其添加到他們的「願望清單」中。報告可以用當前的願望清單打印。如果DVD標題包含序號(第一,第二,第三,第四等),則我的客戶想要按數字(1,2,3,4等)進行排序。如何排序包含序號的文本?

例如,如果該腳本用於創建,填充和查詢表:

CREATE TABLE Dvd (
    TitleID INT IDENTITY PRIMARY KEY 
    ,Title VARCHAR(256) 
) 

GO 

INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete First Season') 
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Second Season') 
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Third Season') 
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Fourth Season') 

SELECT Title FROM Dvd ORDER BY Title 

查詢返回的結果如下:

 
M*A*S*H - The Complete First Season 
M*A*S*H - The Complete Fourth Season 
M*A*S*H - The Complete Second Season 
M*A*S*H - The Complete Third Season 

沒有任何人有一個什麼建議有效的方法來分類標題,以便按照與序號文本相關的實際編號的順序列出它們:

 
M*A*S*H - The Complete First Season 
M*A*S*H - The Complete Second Season 
M*A*S*H - The Complete Third Season 
M*A*S*H - The Complete Fourth Season 

回答

1

假設TitleID的順序增加,只需按TitleID排序。