How to modify the parameter values of the value function?

I have a value function strfunc1
lj=lj+dbo.strfun2('string1')
lj=lj+dbo.strfun2('string2')
......
I want to get a string SSTR now
If CHARINDEX('string1',sstr)>0 replace(sstr,'string1','')
Want to do in the strfun2 function, how to do?

mssql

Started by Ed at November 15, 2016 - 10:45 AM

create function strfun2(@str1 nvarchar(100),@str nvarchar(100))
returns nvarchar(100)
as
begin

return case when charindex(@str1,@str)>0 then replace(@str,@str1,'') else @str end
end
go

select dbo.strfun2('1','321')



Such?

Posted by Mortimer at November 17, 2016 - 11:15 AM

Whether or not replaced once,
sstr=replace(sstr,'string1','')

Posted by Dana at November 18, 2016 - 12:14 PM

CREATE FUNCTION strfun2(@source VARCHAR(100),@match VARCHAR(100))
RETURNS NVARCHAR(100)
AS
BEGIN
	SELECT @source=replace(@source,@match,'')
	RETURN @source;
END


SELECT dbo.strfun2('abcb','b')

Posted by Drew at November 24, 2016 - 1:13 PM