Ankit  Shukla

Ankit Shukla

  • NA
  • 681
  • 116.1k

Problem in table valued function in sql

Dec 23 2019 1:03 AM
Hello,
 
My function is:
 

create FUNCTION [dbo].[Split_cognos]
(
@String NVARCHAR(max), --New Value
@Delimiter NVARCHAR(5)
)
RETURNS @SplittedValues TABLE
(
OccurenceId SMALLINT IDENTITY(1,1),
SplitValue NVARCHAR(max)
)
AS
BEGIN
DECLARE @SplitLength int


WHILE LEN(@String) > 0
BEGIN
SELECT @SplitLength = (CASE CHARINDEX(@Delimiter,@String) WHEN 0 THEN
LEN(@String) ELSE CHARINDEX(@Delimiter,@String) -1 END)


INSERT INTO @SplittedValues
SELECT SUBSTRING(@String,1,@SplitLength)


SELECT @String = (CASE (LEN(@String) - @SplitLength) WHEN 0 THEN ''
ELSE RIGHT(@String, LEN(@String) - @SplitLength - 1) END)
END
RETURN
END
 
 
When I call this function like :

SELECT SPLITVALUE FROM dbo.Split(N'??????????,????????',',')
 
 
 Output is not converted in NVARCHAR. (Output is : ???????)
 
Please help
 
Thanks

Answers (1)