替换 SQL Server 中的单引号

2021-12-25 00:00:00 error-handling replace sql-server

我在 SQL Server 中有这个函数来替换单引号.

I have this function in SQL Server to replace single quotes.

但是当我插入单引号时,它会在 Replace(@strip,''','')) 上引发错误:

But when I insert a single quote it throws an error on Replace(@strip,''','')):

Create Function [dbo].[fn_stripsingleQuote]
    (@strStrip varchar(Max))
    returns varchar
as
begin
    declare @CleanString varchar(Max)
    SET @var=(Replace(@strip,'',''))

    return @var
end

推荐答案

您需要按如下方式将单引号加倍:

You need to double up your single quotes as follows:

REPLACE(@strip, '''', '')

相关文章