A partire da SQL Server 2008
puoi usare parametri con valori di tabella:
CREATE TYPE [dbo].[TableType] AS TABLE(
[ID] [INT] NULL
)
GO
CREATE FUNCTION fnTest
(
@t [dbo].[TABLETYPE] READONLY
)
RETURNS INT
AS
BEGIN
RETURN (SELECT TOP 1 ID FROM @t ORDER BY id DESC)
END
GO
DECLARE @t [dbo].[TABLETYPE]
INSERT INTO @t
VALUES ( 1 ),
( 2 )
SELECT dbo.fnTest(@t) AS ID
Uscita:
ID
2