troubleshooting Question

How do I only include an "and" statement in a where clause if a variable has a value in it?

Avatar of LukePerrin01
LukePerrin01 asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008
9 Comments1 Solution188 ViewsLast Modified:
How do I only include an "and" statement in a where clause if a variable has a value in it? I need to modify a real long stored procedure and I only want it to match an Id if that varibale has a value, I saw some examples of using a case statement but cant figure out how to get it working. If the variable string is empty then I want to execute the other stuff in the where clause otherwise I want to retrieve back a specific record to match the variable.

Thanks
Luke
ASKER CERTIFIED SOLUTION
Imran Javed Zia
Consultant Software Engineer - .NET Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 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 9 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