Advertisement

11.01.2007 at 08:43PM PDT, ID: 22934078
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

I need to renumber rows in a table.

Asked by NTJOCK in MS SQL Server

Tags: , , ,

I have a user table in my database.  It consists of the following fields:
UID (varchar)
datecreated (varchar)
useremail (varchar)
name (varhcar)
address (varchar)
[several other fields that are not important]

for whatever reason I did not use an autonumber at the time I created the table.  SQL will not allow it to be converted ( i get error messages).  Please do not focus in on that.  I'm not looking for a solution involving breaking my index and relationships.  I have two other tables that are tied to this one based on the UID field.

I have used a manual index to generate my userID's.  This works well for the most part.  Another table holds numbers, one to a record.  I retrieve the number, increment it and set the next number to be used back in the table.

The catch, and my problem, is that sometimes numbers would get skipped if there was a data writing error.  A combination of bad input, poor error control, and some particularly vicious robots that have created 20 and 30 empty accounts at a whack on my particular site.

The end result is that I have data that looks like this:
UID   - Name
1        PersonA
5        PersonB
6       PersonC
10    PersonD

What I want to do is renumber my UID column.  I propose to use the datecreated column to hold a new ID number.  Then I'll update UID=datecreated and then set datecreated back to null.  Datecreated was intended for a purpose and has not been implemented so the column is empty.

I have tested this on a single account using a single update statement.  It worked fine and didn't break any of the management tools we use to manage users.

Where I am stumped is the code to generate the sequential numbers using SQL.

I've searched and can't find anything to use as an example.

If I were writing it in Basic..... or VBscript it would go:  
A hashed up version of what I want to do is this:
for a=1 to numrows(recordset)
set datecreated=a
next

I suppose I could use a cursor.... it's a one time problem to be fixed once.  Just wondering if anyone has a better way.

We fixed the data entry problem by adding some controls and implementing CAPTCHA to stop the robots.Start Free Trial
[+][-]11.01.2007 at 09:18PM PDT, ID: 20198407

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.02.2007 at 04:26AM PDT, ID: 20199633

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: renumber, sql, rows, number
Sign Up Now!
Solution Provided By: snehsoni
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628