I followed the sample in SQL Server Books Online but it does'nt give me the correct simple sorting of DueDates. Here is my code:CREATE TABLE #Step ( [BuyerCode] [char] (10) NOT NULL , [PartCode] [char] (3) NULL , [DueDate] [datetime] NOT NULL ) Insert Into #Step values ( 'P02-5022', 'MA', '01/10/2001 00:00:00.000' )Insert Into #Step values ( 'P02-5022', 'BTO', '12/16/2015 00:00:00.000' ) Insert Into #Step values ( 'P02-5022', 'MA', '03/17/2005 00:00:00.000' ) Insert Into #Step values ( 'P02-5022', 'MA', '12/23/2003 00:00:00.000' ) Insert Into #Step values ( 'P02-5022', 'RES', '02/14/1999 00:00:00.000' ) IF EXISTS (SELECT name FROM sysindexes WHERE name = 'Order_BuyerCodeDueDate') DROP INDEX #Step.Order_BuyerCodeDueDate CREATE INDEX Order_BuyerCodeDueDate ON #Step (BuyerCode,DueDate) SELECT * FRom #StepDrop Table #Step
Returned Result:BuyerCode PartCode DueDate ---------- -------- --------------------------- P02-5022 MA 2001-01-10 00:00:00.000P02-5022 BTO 2015-12-16 00:00:00.000P02-5022 MA 2005-03-17 00:00:00.000P02-5022 MA 2003-12-23 00:00:00.000P02-5022 RES 1999-02-14 00:00:00.000(5 row(s) affected)
The result should be sorted by DueDates.What will I do?Thank you.