I am trying to write a stored procedure to which I can pass a column name and an unwanted character, and the stored procedure will remove all instances of that unwanted character in the column.
The following SQL is the basis for my stored procedure and works when I execute it from the SQL Server Management Studio:
UPDATE MyTable
SET MyField = REPLACE(MyField, 'T', '');
But if I write a stored procedure, thus:
CREATE PROCEDURE uspRemoveCharFromColumn
@Fieldname nvarchar(50),
@UnwantedChar char(1)
AS
BEGIN
UPDATE MyTable
SET @Fieldname = REPLACE(@Fieldname, @UnwantedChar, '');
END
And execute it, thus:
EXEC uspRemoveCharFromColumn 'ADDR', 'T';
SELECT ADDR
FROM MyTable
WHERE ADDR LIKE '%T%';
I find that none of the "T"s have been removed from any of the field contents in the column.
I have spent the last 45 minutes Google-ing for a reason my stored procedure won't work and have come up empty. Can anyone help?