It seems that an Inline Table-Valued Function cannot include multiple statements.
Check if these variants work in your environment:
-- Inline Table-Valued Function
CREATE FUNCTION dbo.fn_Interval (
@XYZ VARCHAR(32),
@startDate DATE,
@endDate DATE,
@Count INT,
@outputType INT
)
RETURNS TABLE
AS RETURN (
SELECT GETDATE() "Today", DATEADD(DAY, 1, GETDATE()) "Tomorrow"
where @outputType = 1
union all
SELECT GETDATE(), null
where @outputType = 2
union all
SELECT GETDATE(), DATEADD(DAY, -1, GETDATE())
where @outputType not in (1,2)
)
You can also use CASE or IIF inside a single SELECT.
Or:
-- Multi-Statement Table-Valued Function
CREATE FUNCTION dbo.fn_Interval (
@XYZ VARCHAR(32),
@startDate DATE,
@endDate DATE,
@Count INT,
@outputType INT
)
RETURNS @t TABLE (Today date, Tomorrow date)
begin
IF @outputType = 1
insert @t
select GETDATE(), DATEADD(DAY, 1, GETDATE())
else if @outputType = 2
insert @t
SELECT GETDATE(), null
else
insert @t
SELECT GETDATE(), DATEADD(DAY, -1, GETDATE())
return
end
If you want to return a different set of columns depending on parameters, then consider procedures instead of functions.