I have a simple custom type for use it as table valued parameter. Like this:
CREATE TYPE dbo.PeriodsList AS TABLE
(
PeriodDate NVARCHAR(8) NOT NULL
)
I also have very simple table valued function:
alter FUNCTION GetPeriodsInYear (@periods dbo.PeriodsList READONLY) returns @PeriodsSet Table(period NVARCHAR(8))
BEGIN
insert @PeriodsSet
select
'0' as period
Return
end
But when I try to execute this function in this way
DECLARE @periods1 dbo.PeriodsList
INSERT INTO @periods1
VALUES ('20130916')
select * from GetPurchasesInYear(@periods1)
I receive error message - "Must declare the scalar variable "@periods1". I have found many examples about stored procedures but not about functions. Is it possible to pass table valued parameters into functions? And where the mistake in my code?