I\'m still learning my ropes with SQL Server and maybe this question sounds very naive/ridiculous. Please bear with me on this. :)
I saw a function in SQL Server defined
A simple code to show you that the REPLACE
can accept values from a table
CREATE TABLE dbo.Test
(
RowID INT IDENTITY(1,1),
Test VARCHAR(20)
)
GO
INSERT INTO dbo.Test VALUES ('James')
INSERT INTO dbo.Test VALUES ('John')
GO
ALTER FUNCTION [dbo].[fn_CleanNumeric]
(
@InputString VARCHAR(500),
@Test VARCHAR(500)
)
RETURNS TABLE
AS
RETURN(
SELECT
REPLACE(@InputString, n.Test, '') AS Test
FROM
dbo.Test n WHERE Test = @Test)
GO
SELECT * FROM [dbo].[fn_CleanNumeric] ('TestJohn','John')
Test
--------
TestT
The SELECT
takes a random value and will check for that string pattern
in the variable @InputString
, thus passing a @Test variable ensures to REPLACE
the right string pattern