2011-06-16 62 views
0

我在SQL Server 2008中使用此代碼創建了一個功能: http://www.logiclabz.com/sql-server/split-function-in-sql-server-to-break-comma-separated-strings-into-table.aspx在SQL Server中創建了一個函數,但不能從SP調用它?

我看到它在我的編程能力>功能>表值函數下DB> 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. 

w ^我在這裏想念的帽子?

回答

3

您需要在select子句中使用該函數作爲表名,因爲它是一個表值函數。

試試這個:

SELECT ItemID 
    FROM StagingCategoryItems 
WHERE ManufacturerID = @ManufacturerID 
    AND CategoryID = @CategoryID 
    AND ItemID IN (SELECT items 
        FROM dbo.Split(@InIds,',')  
       ) 
+0

+1打我給它,你可能想提一些有關表值函數是如何被稱爲VS標量函數 – 2011-06-16 20:25:41

+0

DOH的區別!謝謝,我沒有注意或讀得很透徹。 – Slee 2011-06-16 20:25:43

相關問題