存储过程

时间:2011-03-23 18:33:21

标签: sql-server-2005 stored-procedures

我有一个名为productreview的表格,列productreviewid ,product id ,shopperid ,review,rating

我有另一个名为shopper的表格,列shopperid, shopid, logicalcode,fore name , surname ,postcode, dateof birth

我想创建一个名为productreviewlist的存储过程,其输入参数为

@shopid int,
@forename nvarchar (10),
@surname nvarchar (10),
@postcode nvarchar (10),
@startdate datetime,
@enddate datetime

请帮我创建这个存储过程

1 个答案:

答案 0 :(得分:1)

这是一个开始:

CREATE PROCEDURE productreview_list
(
    @shopid int,
    @forename nvarchar(10),
    @surname nvarchar (10),
    @postcode nvarchar(10),
    @startdate datetime,
    @enddate datetime
)
AS
BEGIN

SELECT r.* FROM productreview r
INNER JOIN shopper s ON s.shopperid = r.shopperid
WHERE s.shopid = @shopid
AND s.forname = @forename
AND s.surname = @surname
AND s.postcode = @postcode
AND (s.dateofbirth <= @enddate AND s.dateofbirth >= @startdate)

END

您必须提供有关实际需要的更多信息(文本比较,您希望每次审核时看到的内容,某些字段是否可选等)。