In fact, I created the User defined table type in sql server 2008. The structure is as follows.
I pass it as a parameter in the function, and this function also returns the type of the table type. I ran into a problem while I declare a variable of this type in a function, inserting some data into it and return this parameter.
Table type structure:
Create Type OfferWithSubscription as Table
(
OfferID int,
OfferUserID int,
OfferImage varchar(200),
OfferExactPrice Decimal(18,2),
OfferContent varchar(max),
OfferTitle varchar(100),
StartDate datetime,
EndDate datetime,
StartTime datetime,
StopTime datetime,
ShowToUser bit,
SubID int,
SubLevel varchar(100)
)
And the function I'm trying to create:
CREATE FUNCTION FN_ShowOffer
(
@Gold int,
@Silver int,
@Bronze int,
@table dbo.OfferWithSubscription Readonly )
RETURNS dbo.OfferWithSubscription
AS
BEGIN
DECLARE @ReturnTable AS dbo.OfferWithSubscription;
Declare @Case as varchar(20)
if(@Gold=0 and @Silver=1 and @Bronze=0 )
begin
set @Case='1S'
end
if(@Case='1S')
Begin
insert into @ReturnTable
select OfferID, OfferUserID, OfferImage,
OfferExactPrice, OfferContent,
OfferTitle, StartDate, EndDate,
StartTime, StopTime, ShowToUser,
SubID, SubLevel
from @table
where SubID=4
End
RETURN (
@ReturnTable
)
END