troubleshooting Question

Updating the values in a column based on existing values

Avatar of Morpheus7
Morpheus7 asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
9 Comments1 Solution157 ViewsLast Modified:

I would like to be able to update fields in a table and I believe that the following code will make the changes but I am not sure how to code the update to apply it to the table. Value1 forms part of a primary key

      DECLARE @NewCheckDigit INT
      DECLARE @Value1 VARCHAR(14)

      IF SUBSTRING(@Value1 ,3,1) = '9'
                  SET @et_Processed = SUBSTRING(@Value1 ,3,11)
                  SET @et_Processed = SUBSTRING(@Value1 ,3,6) + RIGHT(@Value1 ,5);

      SET @NewCheckDigit = (CONVERT(BIGINT,@et_Processed) % 7) + 1

      IF SUBSTRING(@Value1 , 3,1) = '9'
                  SET @Value1  = @Value1  + @NewCheckDigit
                  SET @Value1  = STUFF(@Value1 ,9,1,@NewCheckDigit)

Any help would be appreciated
Vitor Montalvão
IT Engineer
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros