1

Possible Duplicate:
Cannot find either column “dbo” or the user-defined function or aggregate “dbo.Splitfn”, or the name is ambiguous

--function that parses an array based on any delimiter

CREATE FUNCTION valuedfunction
(
    @string VARCHAR(MAX),
    @delimiter CHAR(1)
)
RETURNS @output TABLE(
    data VARCHAR(256)
)
BEGIN

    DECLARE @start INT, @end INT
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)

    WHILE @start < LEN(@string) + 1 BEGIN
        IF @end = 0 
            SET @end = LEN(@string) + 1

        INSERT INTO @output (data) 
        VALUES(SUBSTRING(@string, @start, @end - @start))
        SET @start = @end + 1
        SET @end = CHARINDEX(@delimiter, @string, @start)
    END

    RETURN

END

--stored procedure that supports a comma separated value list of employee IDs. I use the function ---(valuedfunction) to get the employee data.

CREATE PROCEDURE commaseparated  
@keyList varchar(40) 
AS 
SELECT Title, Birthdate 
FROM HumanResources.Employee WITH (NOLOCK) 
WHERE EmployeeID IN (dbo.valuedfunction(@keyList))  

--This is the problem: I am getting errors below: What am I missing
exec commaseparated '10,11,12,13';

--ERROR MESSAGE: Msg 4121, Level 16, State 1, Procedure commaseparated, Line 4 Cannot find either column "dbo" or the user-defined function or aggregate "dbo.valuedfunction", or the name is ambiguous.

Community
  • 1
  • 1
Yves
  • 12,059
  • 15
  • 53
  • 57

1 Answers1

1

Write

WHERE EmployeeID IN (select data  from dbo.valuedfunction(@keyList)) 
Magnus
  • 45,362
  • 8
  • 80
  • 118