View Single Post
  #1 (permalink)  
Old 12-05-2006, 11:25 PM
Pureke
 
Posts: n/a
Default MS SQL dialect question:

How to select highest value and then create new object with that value +1?


I'm a real newb on sql and can't find any solution to my problem.
I'm having a db with a table Item and in that table are quite a few collumns.
One of them is named IID
What I want to do is the following:
Select the highest IID, then add 1 (say the max IID is 50, I want to use 51) and fill in all the collumns.
I know how to select that highest IID, I know how to fill in all the other values, I just can't figure out how to add 1 to that IID :s

I have this:
SELECT *
FROM Item
WHERE IID = (SELECT MAX(IID) FROM Item)

INSERT INTO Item
(IID, all the rest of the collumns here )
VALUES ( no idea what will come here, again all the rest of the values here)


I'm pretty sure I'll need some extra stuff to make it work but again, I can't figure it out

Thx already
Edit/Delete Message Reply With Quote

ANSWER(S):