continuous counter..?

  • Hey, this is my first post.

    http://www.sqlservercentral.com/forums/images/emotions/blush.gif .

    I am developing a integration protype and I am assigning a "make beleive" primary key, which I currently do by assigning a counter number in a cursor. This works fine....but the next time around the program runs I want the counter to start at + 1 from the last number assigned. Any suggestions would be apprecaited.

    Thanks,

    Jay

  • Why not use an identity column?

    You can always use something like this... but you must lock the table for inserts when you do this :

    Select @MyNewID = ISNULL(MAX(IdCol), 0) + 1 from dbo.Mytable

    Insert into dbo.Mytable (IdCol) VALUES (@MynewID)

  • The easy way to lock this is use a transaction around it.

    Begin transaction

    ...

    commit

  • Thanx... forgot to type that .

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply