SQL Server:存储过程相关

时间:2011-03-23 17:04:39

标签: sql sql-server stored-procedures

我有两个输入参数shopidcategoryid

我想为categoryproductlist创建一个存储过程,用于显示与categoryid相关的产品。我有一个包含product列的表productid , shopid , title,我有一个表category,其中列shopid,title,logical code, categoryid

有人能告诉我如何使用这些输入参数为categoryproductlist编写存储过程吗?

1 个答案:

答案 0 :(得分:2)

快来看看:

CREATE PROCEDURE p_CategoryProductList
    @CategoryID INT
    @ShopID     INT

AS

SELECT
    c.itle as CategoryTitle,
    c.[logical code],
    p.title as ProductTitle
FROM Product p
INNER JOIN tblcategoryproduct cp on p.ProductID=cp.ProductID
INNER JOIN Category c on c.CategoryID=cp.CategoryID
WHERE c.ShopID=@ShopID
AND   c.CategoryID=@CategoryID