Skip to content
Advertisement

Converting a C# SQL string into a SQL stored procedure

In my C# code I have the following piece of code that I am looking at converting into SQL in a stored procedure:

What I am trying to do is find a clean, easier way to make these “and” conditionals in C# fit into a SQL procedure without having to make 16 long difficult to read if and if else’s or a large amount of CASE statements to cover every single combination.

Maybe I am a victim of wishful thinking here, but I thought maybe I am missing something that would simplify this conversion. Thanks !

Advertisement

Answer

One possible solution might be to use CASE WHEN ELSE in the WHERE clause

This is not very sufficient on large tables but does what you need in just one query.

To call the procedure, use

To assign db NULL you can do

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