Question : MS SQL SP if ID = 1 then where price < 25.00

Hello Experts,

Sure that I need to use CASE to build this query, but not sure how,

I have 4 variables that get sent using the ID parameter - ID = 1, ID = 2, ID = 3, ID = 4

I have the SP (part built) (AND S.Price ) below -

What I need to do is if ID = 1, then where S.Price  < 25.00 or if ID = 2 where S.Price between 25.00 AND 35.00 OR if ID = 3 where S.Price between 35.00 AND 50.00 or if ID = 4 where S.Price > 50.00

Hope that makes sense?

Please advise?

Thank you
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
USE [NewFlorist]
GO
/****** Object:  StoredProcedure [dbo].[HomePageProducts]    Script Date: 07/22/2010 16:28:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ProductPriceSearch] 
@SiteID int,
@ID int
AS
BEGIN
SET NOCOUNT ON;
select
P.ID ProductiD, 
P.ProductName,
P.ProductPhoto,
LEFT(P.ProductDescription, 44) +'...' ProductDescription,
S.Price
from dbo.Product P
inner join dbo.ProductSelect S
on S.ProductID = P.ID
where 
P.FloristID = @SiteID 
and P.HP = 'Y' 
and S.PriceDescription = '1'
AND S.Price 
END

Answer : MS SQL SP if ID = 1 then where price < 25.00

actually the second between will not be the best approach because it will consider both ends of the interval so @ID 2 and 3 will overlap.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
USE [NewFlorist]
GO
/****** Object:  StoredProcedure [dbo].[HomePageProducts]    Script Date: 07/22/2010 16:28:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ProductPriceSearch] 
@SiteID int,
@ID int
AS
BEGIN
SET NOCOUNT ON;
select
P.ID ProductiD, 
P.ProductName,
P.ProductPhoto,
LEFT(P.ProductDescription, 44) +'...' ProductDescription,
S.Price
from dbo.Product P
inner join dbo.ProductSelect S
on S.ProductID = P.ID
where 
P.FloristID = @SiteID 
and P.HP = 'Y' 
and S.PriceDescription = '1'
AND (	(@ID = 1 and S.Price < 25) or
	(@ID = 2 and S.Price >= 25 and s.Price < 35) or
	(@ID = 3 and S.Price between 35 and 50) or
	(@ID = 4 and S.Price >= 50)
)
END
Random Solutions  
 
programming4us programming4us