值函数里如何修改参数的值?
我有一个值函数strfunc1
lj=lj+dbo.strfun2('string1')
lj=lj+dbo.strfun2('string2')
......
我现在想搞一个字符串 sstr
如果charindex('string1',sstr)>0 replace(sstr,'string1','')
想做在strfun2函数里,怎么做好?
mssql
[解决办法]
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')
sstr=replace(sstr,'string1','')
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')