Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 insert order Issue

Author  Topic 

itmaster
Starting Member

28 Posts

Posted - 2013-08-08 : 16:09:03
Hi,
I have a few recodes that I want to put in, but they want it stay in the order that is in the table now; and the table has an identity field on it.
So for example the curretnt records are as follows:

ID Code Description DateEntered
1 V237 TestA 2012-04-21 10:17:00
2 V238 TestB 2012-06-23 09:17:00

and not they want to enter the following records:

V239 TestdC 2012-04-21 10:17:00
V240 TestS 2012-06-23 09:17:00

So After the in sert it looks like this:

1 V237 TestA 2012-04-21 10:17:00
2 V238 TestB 2012-06-23 09:17:00
3 V239 TestdC 2012-04-21 10:17:00
4 V240 TestS 2012-06-23 09:17:00

Currently if I do this the records that I insert go some where in the table, but not in this order
ANy ideas on how I can do this?
Thank you

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-08-08 : 16:34:56
How are you inserting the data?
Go to Top of Page

itmaster
Starting Member

28 Posts

Posted - 2013-08-08 : 16:39:41
Just a standard insert and not including the Ident field
INSERT INTO TableA VALUES (' V237','TestA',GETDATE)
Go to Top of Page

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-08-08 : 16:58:26
Try this:
[CODE]
INSERT INTO TableA(code, description, dateentered) VALUES ('V237','TestA',GETDATE);
[/CODE]

When you insert a row is the ID incrementing correctly? and what is the value?
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2013-08-09 : 08:09:07
It is important to realize that, by definition, the rows in a relational DB table are unordered.

If you want to order the rows then you should use the ORDER BY clause when the data is retrieved.

In your case, it looks as though:

SELECT ID, Code, Description, DateEntered
FROM YourTable
ORDER BY ID

should produce the rows in the order they were entered.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-08-09 : 12:12:45
It looks like the IDs are in the correct order. Are you saying that you want the database to shuffle the IDs around based on the DateEntered? If so, it ain't gunna happen without manual code.
Go to Top of Page

ShivaKrishna
Starting Member

20 Posts

Posted - 2013-08-28 : 07:15:43
you can insert as your wish...while retrieving,you can retrieve as per your need...please give more clarity in your question
Go to Top of Page
   

- Advertisement -