Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 10 product id's stored in my database table which has few other columns..but i want to retrieve only the id column from the database and want to update the id which are still empty??

for example if some data is stored in 1,2,3,4,6,8,10 id's whenever i update a new product i want it to be automatically stored at 5th id and next one at 7th id..
is it possible?
Posted
Updated 30-Mar-10 22:38pm
v2

If the column id is of identity type then its not possible to specify your id, in case its not then you can write a function which returns the smallest missing id from the id column.

You can use following query to get the smallest missing id from you table.

Select Top 1 ID + 1 from YourTable T1
where not exists 
   (select * from YourTable T2 where T2.ID = T1.ID + 1)
 
Share this answer
 
Hey,

Is there any reason for this approach?

Because it sounds potentially dangerous to me. It could lead to false references if tables are not properly related. Besides that, new rows will always be added to the bottom (as far as i know atleast!)

It all depends on the ID being an AutoNumber or not.
 
Share this answer
 
v2
i have changed the application so that it can be easily done...now i only want the id number to be generated whichever is empty in 10 and display and store that id in a offset column without adding any new row...is it possible??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900