实际上我在 sql server 2008 中创建了一个用户定义的表类型。结构如下所示。
我将它作为函数中的参数传递,并且该函数也返回该类型的表类型。我正面临这个问题,而我在函数中声明了该类型的变量,在其中插入了一些数据并返回了该参数。
表类型结构为:
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)
)
我想要创建的功能是:
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