In the future, we will perform multi-condition queries. One is arrangement and combination, and the other is dynamic concatenation of SQL statements.
For example, we need two conditions: one is date @ adddate and the other is @ name.
The first method is
If (@ adddate is not null) and (@ name <> '')
Select * from table where adddate = @ adddate and name = @ name
Else if (@ adddate is not null) and (@ name = '')
Select * from table where adddate = @ adddate
Else if (@ adddate is null) and (@ name <> '')
Select * from table where and name = @ name
Else if (@ adddate is null) and (@ name = '')
Select * from table
The second type is dynamic composition of SQL, which is executed through exec and I will not write it,
Yesterday I thought of a way
Select * from table where (adddate = @ adddate or @ adddate is null) and (name = @ name or @ name = '')
Result 1: debugging is successful,
Please advise if you have any ideas and better methods !~