January 12, 2008 at 3:31 am
need help on how to update a string in a table column. I want to replace 'Brodmann-10' with 'Brodmann-1910'. The following script does not work right. I appreciate your help:)
DECLARE @FindString varchar(80)
DECLARE @ReplaceString varchar(80)
SET @FindString = 'Brodmann-10'
SET @ReplaceString = 'Broadmann-1910'
SET NOCOUNT ON
DECLARE @TextPointer varbinary( 16 )
DECLARE @DeleteLength int
DECLARE @OffSet int
SELECT @TextPointer = textptr( Description)
FROM Brodmann --Brodmann is a table only has 5 rows
SET @DeleteLength = len( @FindString )
SET @OffSet = 0
WHILE ( SELECT count( * ) FROM Brodmann WHERE charindex( '%Brodmann-10%', Description) <> 0) > 0
BEGIN
SELECT @OffSet = charindex( '%Brodmann-10%', Description) -1
FROM Brodmann
WHERE charindex('%Brodmann-10%', Description) <> 0
UPDATETEXT Brodmann.Description
@TextPointer
@OffSet
@DeleteLength
@ReplaceString
END
RETURN
January 12, 2008 at 8:11 am
I would use something like:
UPDATE TABLENAME
SET COLUMN = REPLACE(COLUMN,'Brodmann-10','Brodmann-1910')
WHERE COLUMN LIKE '%Brodmann-10%'
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply