在存储过程中,将数组传递给值为Function的表以进行解析

时间:2012-10-08 19:24:42

标签: tsql

  

可能重复:
  Cannot find either column “dbo” or the user-defined function or aggregate “dbo.Splitfn”, or the name is ambiguous

- 基于任何分隔符

解析数组的函数
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

- 支持逗号分隔的员工ID值列表的存储过程。我使用函数---(valufunction)来获取员工数据。

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

- 这是问题所在:我收到的错误如下:我错过了什么     exec commaseparated&#39; 10,11,12,13&#39 ;;

- 错误消息: Msg 4121,Level 16,State 1,Procedure commaseseparated,Line 4 找不到任何一列&#34; dbo&#34;或用户定义的函数或聚合&#34; dbo.valuedfunction&#34;,或名称不明确。

1 个答案:

答案 0 :(得分:1)

WHERE EmployeeID IN (select data  from dbo.valuedfunction(@keyList))