Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a table with Order by not working properly

Status
Not open for further replies.

Wyldcard9

Programmer
Feb 5, 2004
82
US
Here is my code:

DELETE FROM [ENROLLMENT].[dbo].[Process]
DECLARE @socnums varchar(25)
DECLARE @doctype varchar(10)
DECLARE @sigdate datetime
DECLARE @fundnum varchar(10)
DECLARE @create_date datetime
DECLARE @memberno varchar(25)

DECLARE the_cursor CURSOR FOR
SELECT ID_1006, ID_1007, ID_1015, ID_1002, ID_502, ID_1005 FROM ELVIS.EP3_14
WHERE ISNUMERIC(ID_1005) = 1
and ID_12 > -1
ORDER BY ID_1005 ASC,
ID_1015 ASC
OPEN the_cursor
FETCH NEXT FROM the_cursor into @socnums, @doctype, @sigdate, @fundnum, @create_date, @memberno

WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO [ENROLLMENT].[DBO].[Process] (SSN, DOCTYPE, SIGDATE, FUNDNUM,
CREATE_DATE, MEMBERNO)
VALUES(@SOCNUMS, @DOCTYPE, @SIGDATE, @FUNDNUM, @CREATE_DATE, @MEMBERNO)

FETCH NEXT FROM the_cursor into @socnums,@doctype,@sigdate,@fundnum,@create_date,@memberno
END
CLOSE the_cursor
DEALLOCATE the_cursor
GO

I am trying to populate a table that I use as a file on the mainframe. I wanted to sort the table the same way a file I will be comparing it to on the mainframe is sorted. I view the table, and for some reason it is not sorted ascending by ID_1005, and then ID_1015. The results look partially sorted. Can anyone offer any assistance? Can I sort the table later with another program?
 
Do you have a clustered index on the table you are populating? Got to the table in Enterprise Manager and right-click on it. From there choose All Tasks..Manage Indexes. Check if there is a clustered index on another field that is not the field you are importing "ID_1005" into.

Thanks

J. Kusch
 
J. Kusch,

Thanks. There are no clustered indexes at all under All Tasks..Manage Indexes for that table. Do I need to add one for ID_1005?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top