我已经编写了将多个参数传递给where子句中的查询的函数,但是现在我遇到了性能问题。
我需要避免该函数传递多个参数。
CREATE FUNCTION [dbo].[UTILfn_Split] (@String NVARCHAR(max), @Delimiter VARCHAR(10))
RETURNS @ValueTable TABLE ([Value] NVARCHAR(max))
BEGIN
DECLARE @NextString NVARCHAR(max)
DECLARE @Pos INT
DECLARE @NextPos INT
DECLARE @CommaCheck NVARCHAR(1)
--Initialize
SET @NextString = ''
SET @CommaCheck = right(@String, 1)
--Check for trailing Comma, if not exists, INSERT
--if (@CommaCheck <> @Delimiter )
SET @String = @String + @Delimiter
--Get position of first Comma
SET @Pos = charindex(@Delimiter, @String)
SET @NextPos = 1
--Loop while there is still a comma in the String of levels
WHILE (@pos <> 0)
BEGIN
SET @NextString = substring(@String, 1, @Pos - 1)
INSERT INTO @ValueTable ([Value])
VALUES (@NextString)
SET @String = substring(@String, @pos + 1, len(@String))
SET @NextPos = @Pos
SET @pos = charindex(@Delimiter, @String)
END
RETURN
END
当前,我正在使用函数传递多个参数,如下所示,但我需要提高查询性能,避免在查询中使用该函数。有没有办法传递没有功能的多个参数?