USE [aardvark_WetsuitReview]
GO
/****** Object: StoredProcedure [wetsuit].[wsp_BuildProdSearch] Script Date: 07/07/2010 19:37:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: nick
-- Create date: 6/7/10
-- Description: get all product details dynamic type query
-- =============================================
ALTER PROCEDURE [wetsuit].[wsp_BuildProdSearch]
-- Add the parameters for the stored procedure here
@prod int = null,
@season int = null,
@sport int = null,
@brand int = null,
@age int = null
-- exec wsp_BuildProdSearch @prod = 3, @season = 2, @sport = 2, @brand = 1, @age = 1
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT DISTINCT a.name, a.price, a.thickness, e.brandName, f.genderAge, LEFT(g.brandProdDesc,150) as brandProdDesc,
h.img1, h.img2, h.img3, h.img4, h.img5
from t_product a
join tx_productType b on a.id = b.productID
and (b.type1 = @prod or b.type2 = @prod or b.type3 = @prod or b.type4 = @prod or @prod is null)
join tx_season c on a.id = c.productID
and (c.season1 = @season or c.season2 = @season or c.season3 = @season or @season is null)
join tx_sportType d on a.id = d.productID
and (d.sportType1 = @sport or d.sportType2 = @sport or d.sportType3 = @sport or @sport is null)
join t_brand e on a.brandID = e.id
and (a.brandID = @brand or @brand is null)
join t_genderAge f on a.genderAgeID = f.id
and (a.genderAgeID = @age or @age is null)
join t_brandDesc g on a.ID = g.prodID
join t_images h on a.imgID = h.id
and a.live = 1
END
GO
|