I am trying to execute a store Procedure but not able to fetch the data from it. Below is the Store Procedure.
USE test
GO
CREATE PROCEDURE SELECT_IDs @idList nvarchar(1750)
AS
BEGIN TRY
SELECT DISTINCT child FROM example WHERE parent IN (@idList)
UNION
SELECT DISTINCT parent FROM example WHERE child IN (@idList)
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber;
END CATCH
GO
EXEC SELECT_IDs @idList = ['100','101'];
After executing the above procedure it is giving me no data where as if i run the same select query it is giving me data.
SELECT DISTINCT child FROM example WHERE parent IN ('100','101')
After reading the comments i tried the below code but not working.
/*
Splits string into parts delimitered with specified character.
*/
CREATE FUNCTION [dbo].[SDF_SplitString]
(
@sString nvarchar(2048),
@cDelimiter nchar(1)
)
RETURNS @tParts TABLE ( part nvarchar(2048) )
AS
BEGIN
if @sString is null return
declare @iStart int,
@iPos int
if substring( @sString, 1, 1 ) = @cDelimiter
begin
set @iStart = 2
insert into @tParts
values( null )
end
else
set @iStart = 1
while 1=1
begin
set @iPos = charindex( @cDelimiter, @sString, @iStart )
if @iPos = 0
set @iPos = len( @sString )+1
if @iPos - @iStart > 0
insert into @tParts
values ( substring( @sString, @iStart, @iPos-@iStart ))
else
insert into @tParts
values( null )
set @iStart = @iPos+1
if @iStart > len( @sString )
break
end
RETURN
END
And Modified the stored Procedure to
USE test
GO
CREATE PROCEDURE SELECT_IDs @idList nVarchar(2048)
AS
BEGIN TRY
SELECT DISTINCT child FROM example WHERE parent IN ([dbo].[SDF_SplitString]
('@idList',',')) or child IN ([dbo].[SDF_SplitString]('@idList',','))
UNION
SELECT DISTINCT parent FROM example WHERE parent IN ([dbo].[SDF_SplitString]
(@idList,',')) or child IN ([dbo].[SDF_SplitString](@idList,','))
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber;
END CATCH
GO
But getting the issue : Cannot find either column "dbo" or the user-defined function or aggregate "dbo.SDF_SplitString", or the name is ambiguous.