我使用SQL Server 2016. 我想編寫一個函數,它將一個表作爲參數,然後在該表上執行與另一個表的連接。 我宣佈以下類型:將表作爲參數並執行連接的表值函數
CREATE TYPE WorklistTable AS TABLE (WorklistId int NOT NULL)
然後我用它了很多基於某些條件做選擇功能
CREATE FUNCTION [dbo].[fnGetSomeData] (
@WorklistIds WorklistTable readonly
)
RETURNS TABLE
AS RETURN
(
select WorklistId, wlu.UserId
from @WorklistIds
join [dbo].[WorklistUser] wlu on wlu.WorklistId = @WorklistIds.worklistId
-- the rest is omitted
);
我收到以下錯誤:
Must declare the scalar variable "@WorklistIds".
我試圖聲明變量,但出現錯誤:
The variable name '@WorklistIds' has already been declared. Variable names must be unique within a query batch or stored procedure.
感謝。像魅力一樣工作。我會接受你的回答。 – Dido