Multi-statement table-valued functions
Emulating table-valued functions with more than one statement can get messy. We use a chain of CTEs, grouping compatible statements to end up with the simplest possible output.
Code examples
SQL Server:
CREATE FUNCTION dbo.ExampleTVF_InsertSkipNull()
RETURNS @Result TABLE
(
Value NVARCHAR(50) NULL,
Extra NVARCHAR(50) NULL
)
AS
BEGIN
INSERT INTO @Result (Value, Extra)
VALUES ('First', 'X');
INSERT INTO @Result (Value)
VALUES ('Second');
INSERT INTO @Result (Extra)
VALUES ('Y');
RETURN;
ENDFabric Warehouse (generated by SQL Tran):
SQL Server:
Fabric Warehouse (generated by SQL Tran):
Last updated