Updating the values in a column based on existing values
Posted on 2014-09-01
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