troubleshooting Question

sql if within where

Avatar of R8VI
R8VI asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
17 Comments1 Solution298 ViewsLast Modified:
Hi,

I am getting incorrect syntax near the If statement on this SQL query please help


Select *
  FROM Properties Prop
  Inner join I IMG on Prop.PropertyID = IMG.PropertyId
  WHERE Prop.SaleOrLet = 'Sale' AND IMG.MainImage = 1 AND 
(Prop.Price  >= @PriceMin) AND
(Prop.Price  <= @Price) AND
(@Bedrooms IS NOT NULL OR @Bedrooms = Prop.Bedrooms) AND
(@Postcode = Prop.Postcode)  
or 
(IF @Postcode = '-- Please Select --' BEGIN Prop.PostCode IS NOT NULL END) 

Thanks.

R8VI
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 17 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros