Create FUNCTION [dbo].[fn_GetStockDeatils]()
RETURNS @Results TABLE
(
PurchaseData nvarchar(50) NOT NULL
)
AS
BEGIN
Declare @tableName varchar(25)
Declare @PKKey numeric(18,0)
DECLARE StockCursor CURSOR FOR Select tableName ,PKKey from INVM
OPEN StockCursor
FETCH StockCursor INTO @tableName ,@PKKey
Begin
Insert @Results Select PurchaseData from @tableName.PKKey [email protected]
END
FETCH StockCursor INTO @tableName ,@PKKey
close StockCursor
DEALLOCATE StockCursor
Return
END
我已經寫過這個,但它不能正常工作。 @tableName
包含表格的名稱。如果可能,請幫助我。在UDF中使用光標,返回具有不同表名稱的列
這是一個非常非關係數據設計演示。這會導致你很多像這樣的問題。 – RBarryYoung