我在SQL Server 2008中使用以下代码创建了一个函数: http://www.logiclabz.com/sql-server/split-function-in-sql-server-to-break-comma-separated-strings-into-table.aspx
我在我的数据库中看到它在Programability>功能>表值函数> dbo.Split
但是当我尝试使用我的SP代码调用时:
SELECT ItemID
FROM StagingCategoryItems
WHERE ManufacturerID = @ManufacturerID
AND CategoryID = @CategoryID
AND ItemID IN (
dbo.Split(@InIds,',')
)
我收到此错误:
Msg 4121, Level 16, State 1, Line 11
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Split", or the name is ambiguous.
我在这里缺少什么?
答案 0 :(得分:3)
您需要在select子句中将该函数用作表名,因为它是一个表值函数。
试试这个:
SELECT ItemID
FROM StagingCategoryItems
WHERE ManufacturerID = @ManufacturerID
AND CategoryID = @CategoryID
AND ItemID IN (SELECT items
FROM dbo.Split(@InIds,',')
)