Skip to content
Advertisement

tweaking stored proc

I have a stored proc that gets called with a parameter. I would like to check what the PARAM @Value is, and depending on the value, I want to add a part of a WHERE clause if it equals to a certain value.

Let’s say the proc looks like this:

This is a much simpliefied code, my WHERE clause for @Value=1,2,3 will be much bigger.

So essentially, my goal is to add part of WHERE clause if the @Value = 1, 2, 3. Is something like doable?

EDIT: What if above my select statement i add something like

Advertisement

Answer

You could add the condition :

Or you could write a dynamic SQL.

Alternative:

Last alternative:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement