troubleshooting Question

T-SQL null values in parameters

Avatar of conrad2010
conrad2010 asked on
Microsoft SQL Server 2005SQL
4 Comments1 Solution218 ViewsLast Modified:
this is a simplified query where I am passing a value to @sAlphaGroup but sometimes that value is null and I need to deal with this in one line...

this doesn't work (no records returned where in this case I need all records):

declare @sAlphaGroup varchar(20)
set @sAlphaGroup = null

From dbo.Projects As P
     Join dbo.tblProjectProducts As Product
          On Product.ProjectId = P.ProjectId
      P.IsActive = 1
     And Product.IsActive = 1
     And Product.IsOnWebSite = 1
     AND (@sAlphaGroup IS NOT NULL OR PP.ProductTitle LIKE '[' + @sAlphaGroup + ']%')
Order By

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
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 4 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