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.
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:002 V238 TestB 2012-06-23 09:17:00and not they want to enter the following records: V239 TestdC 2012-04-21 10:17:00 V240 TestS 2012-06-23 09:17:00So After the in sert it looks like this:1 V237 TestA 2012-04-21 10:17:002 V238 TestB 2012-06-23 09:17:003 V239 TestdC 2012-04-21 10:17:004 V240 TestS 2012-06-23 09:17:00Currently if I do this the records that I insert go some where in the table, but not in this orderANy 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? |
|
|
itmaster
Starting Member
28 Posts |
Posted - 2013-08-08 : 16:39:41
|
Just a standard insert and not including the Ident fieldINSERT INTO TableA VALUES (' V237','TestA',GETDATE) |
|
|
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? |
|
|
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, DateEnteredFROM YourTableORDER BY IDshould produce the rows in the order they were entered. |
|
|
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. |
|
|
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 |
|
|
|
|
|
|
|