I am wanting to update the customernum field starting at 211001 and increment by 1. I can't find a script that makes it that simple. The scripts I found are based on another field and I have tried to adjust for that. It is not working. Do you know something I can use for something that simple?

asked 26 Mar, 13:37

HaleYea's gravatar image

HaleYea
112
accept rate: 0%


I assume that column has an AUTOINCREMENT default. You can then

  • either explicitly set the value for an autoincrement column (because it's just a default for that column, and defaults can of course be overriden, so you could just insert the first row with number 211001),

  • or you can use the builtin stored procedure sa_reset_identity() to provide the next value. (Note: The value there is the "last one used", so you would set it to 211000.)

Autoincrements are always incremented by 1. For other steps, you would need a sequence instead.

permanent link

answered 26 Mar, 14:26

Volker%20Barth's gravatar image

Volker Barth
40.2k361549822
accept rate: 34%

edited 26 Mar, 14:27

This is what I found that worked

DECLARE @id INT SET @id = 211001 UPDATE OKF_CUST SET customernum = @id, @id = @id + 1;

permanent link

answered 26 Mar, 15:02

HaleYea's gravatar image

HaleYea
112
accept rate: 0%

Comment Text Removed
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×14

question asked: 26 Mar, 13:37

question was seen: 151 times

last updated: 27 Mar, 07:39