SQL 具有 2 列数组输入的内联函数

SQL inline function with array input with 2 columns

我有一个带有数组输入 (dbo.Invoicenrs_table) 的内联函数,如下所示,如何扩展此函数以在数组输入中包含更多参数(我已经扩展了用户定义的 table 有一个额外的列)并且额外的参数也必须在 select.

FUNCTION  [dbo].[fn_SelectInvoices]
(
      @Invoice_Nrs dbo.Invoicenrs_table READONLY
)
RETURNS TABLE 

AS
RETURN
(      
      SELECT 
      [Invoice_Number] ,
      [Total_value]
    FROM Invoice WHERE [Invoice_Number] IN ( SELECT * from @Invoice_Nrs)
) 

如果您要向 table 类型添加额外的列,并且您现在需要匹配多个列,那么您只需将 WHERE 子句更改为 INNER JOIN 即可匹配任何或 table 参数中包含您的数据 table:

的所有列
ALTER FUNCTION  [dbo].[fn_SelectInvoices]
(
      @Invoice_Nrs dbo.Invoicenrs_table READONLY
)
RETURNS TABLE 

AS
RETURN
(      
      SELECT 
      i.[Invoice_Number],
      i.[Col2],
      i.[Col3]
      i.[Total_value]
    FROM Invoice i
    INNER JOIN @Invoice_Nrs n ON i.[Invoice_Number] = n.[Invoice_Number
                             AND i.[Col2] = n.[Col2]
                             AND i.[Col3] = n.[Col3] --if you end up extending your table type further
                             AND ....
);