Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Search a value and replace with new character in columns

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-11 : 22:40:02
Vishnu writes "I have a table named MYTABLE containing FIELD1 which has 3 sample records.

Vi$$$u
Sam'le
Test
I want to execute a stored procedure that will accept two parameters. First parameter to search and second parameter to replace.

If i execute the stored procedure as follows,

exec Myprocedure "$'" "Kp" then my expected result should be like
ViKKKu
Sample
Test
If i use the following code

create procedure proc1(@find varchar(6),@replace varchar(6))
as
declare @slen int,@currpos int
declare @repchar char(1)
select @currpos=1
select @slen= datalength(@find)
while @currpos <= @slen
begin
select @repchar = substring(@replace,@currpos,1)
update mytable set field1 = isnull(stuff(field1,charindex(substring(@find,@currpos,1),field1),1,substring(@replace,@currpos,1)),field1)
select @currpos=@currpos + 1
end

am getting the following result.

ViK$$u
Sample
Test

Can you help me to solve this????

Thanks"
   

- Advertisement -