Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi all
i need to pull numbers from a string (comments) and if i get 13 numbers then
populate another field, this is to pull
a possible barcode out of a comments field.i've got a working solution, but would like to know if there is a neater solution,
Using SQL 7, in 2000 i would be able to have
a user defined funtion to handle the string without the cursor,any input appreciated
cheers mo
CREATE PROCEDURE spxPPGenerateBarCodes AS
DECLARE @Comments varchar(50)
/* get a list of the comments that were
imported today by spxPPImportNewPartNumber
we can tell these by 'x-' */
DECLARE c1 CURSOR FOR
SELECT Comments
FROM tblItemMaster
WHERE BarCode = 'x-'
AND Comments IS NOT NULLOPEN c1
/* start the loop through table */
FETCH NEXT FROM c1
INTO @CommentsWHILE @@FETCH_STATUS = 0
BEGIN/* we count the length of the comment to
set the lenghth of the loop through to
extract numeric's */
DECLARE @COUNTER integer
SELECT @COUNTER = 1
WHILE (@COUNTER < (LEN(@Comments)+1))
BEGIN
BEGIN
IF ISNUMERIC(SUBSTRING(@Comments,@counter,1)) = 1
/* if we get a numeric we throw
it in the BarCode field */
BEGIN
UPDATE tblItemMaster
SET BarCode = (BarCode + (LTRIM(SUBSTRING(@Comments,@counter,1))))
WHERE Comments = @Comments
END
END
/* increment counter */
SELECT @COUNTER = @COUNTER +1
END
/* keep the loop going */
FETCH NEXT FROM c1
INTO @CommentsEND
/* close and clear the cursor */
CLOSE c1
DEALLOCATE c1/* we now extract our barcode */
BEGIN
UPDATE tblItemMaster
SET BarCode = 'NEW' + RIGHT(BarCode,13)
WHERE LEN(Barcode) = 15
AND LEFT(BarCode,2) = 'x-'
END/* and set the leftovers back to NULL */
BEGIN
UPDATE tblItemMaster
SET BarCode = NULL
WHERE LEFT(BarCode,2) = 'x-'
END
RETURN

![]() |
Zinc Application Framewor...
|
close button, property sh...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |