I had written the function to pass multiple parameters in to query in where clause but now I am facing performance issue.
I need to avoid the function to pass multiple parameter.
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
Currently I am using function to pass multiple parameters like below ,but I need to improve my query performance avoiding the function in the query. Is there any way to pass multiple parameters without function?