在SQL Server中,有一个内置函数为您引用一个名为QUOTENAME的标识符。是否存在相反的功能并再次删除引号?
换句话说,在下面的代码示例中,我将如何替换SOMEFUNCTION以使其为可以初始化@name的任何值返回1?
declare @name nvarchar(50) = 'hello]'
select
case
when SOMEFUNCTION(QUOTENAME(@name)) = @name then 1
else 0
end
答案 0 :(得分:8)
使用PARSENAME
:
declare @name sysname = quotename('foo]');
print @name;
set @name = parsename(@name, 1);
print @name;
[foo]]]
foo]
答案 1 :(得分:0)
首先,创建一个SQL函数:
CREATE FUNCTION dbo.[Revert_QUOTENAME](@quotedvalue As VARCHAR(8000))
RETURNS VARCHAR(8000)
As
BEGIN
RETURN REPLACE(SUBSTRING(@quotedvalue, 2, LEN(@quotedvalue) - 2), ']]', ']')
END
然后,
declare @name nvarchar(50) = 'hello]'
select
case
when [Revert_QUOTENAME](QUOTENAME(@name)) = @name then 1
else 0
end
答案 2 :(得分:0)
您可以在逻辑时使用大小写删除引号或括号。
ctrl.ctrlForm
结果:
this.ctrlForm
答案 3 :(得分:0)
CODE;
ALTER FUNCTION [dbo].[funObtenerSinQuoteName]
(@vchrCadena VARCHAR(8000) , @vchrQuoteNameIni CHAR(1),@vchrQuoteNameFin CHAR(1))
RETURNS VARCHAR(8000) AS
BEGIN
DECLARE @vchrSubCadena VARCHAR (8000), @intCharIndexIni INT,@intCharIndexFin INT
SET @intCharIndexIni=CHARINDEX(@vchrQuoteNameIni,@vchrCadena,0)
SET @intCharIndexFin=CHARINDEX(@vchrQuoteNameFin,@vchrCadena,0)
SET @vchrSubCadena=LTRIM(RTRIM(SubString(@vchrCadena,@intCharIndexIni+1,@intCharIndexFin-@intCharIndexIni-1)))
RETURN @vchrSubCadena
END