下面一种方法是李龙的,属于变通的排序串方法 DDL -------------- CREATE TABLE dbo.Message ( ID numeric(18,0) IDENTITY(1000,1), DateAndTime datetime DEFAULT getdate() NOT NULL, AuthorID numeric(18,0) NOT NULL, Subject nvarchar(250) NOT NULL, Body ntext NULL, LinkURL nvarchar(100) NULL, TextForLink nvarchar(50) NULL, ImageURL nvarchar(100) NULL, Class int DEFAULT 0 NOT NULL, ClientInfo nvarchar(250) NULL, RemoteAddr nvarchar(50) NULL, CONSTRAINT PK_BBSMessage PRIMARY KEY NONCLUSTERED (ID,AuthorID) ) go CREATE TABLE dbo.MsgRefTab ( MsgID numeric(18,0) NOT NULL, ParentID numeric(18,0) NOT NULL, AncestorID numeric(18,0) NOT NULL, ChildNum numeric(18,0) DEFAULT 0 NOT NULL, LinkStr nvarchar(250) NOT NULL, CONSTRAINT PK_BBSRefTab PRIMARY KEY NONCLUSTERED (MsgID) ) go ----------------- 存储过程: ----------------- -- 抽出 CREATE PROCEDURE sp_Summary @HaveBody bit, @from numeric, @to numeric AS IF (@HaveBody = 1) select t.ID,t.DateAndTime,m.Nickname as Author,m.Email,t.Subject,t.Body,t.LinkURL,t.TextForLink,t.ImageURL,s.ChildNu m,s.ParentID from Message t ,MsgRefTab AS s ,(SELECT MsgID FROM MsgRefTab WHERE ParentID = 0) AS f ,Members AS m where t.ID=s.MsgID and f.MsgID = s.AncestorID and f.MsgID between @from and @to and m.MemberID = t.AuthorID order by s.AncestorID,s.LinkStr ELSE select t.ID,t.DateAndTime,m.Nickname as Author,m.Email,t.Subject,t.LinkURL,t.TextForLink,t.ImageURL,s.ChildNum,s.Par entID from Message t ,MsgRefTab AS s ,(SELECT MsgID FROM MsgRefTab WHERE ParentID = 0) AS f ,Members AS m where t.ID=s.MsgID and f.MsgID = s.AncestorID and f.MsgID between @from and @to and m.MemberID = t.AuthorID order by s.AncestorID,s.LinkStr go