Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-03-09 : 08:56:16
|
| Fréderic writes "A store proc makes a select on a table.This proc accepts, say 2 parameters from a search form for filtering the select statement: @p1 and @p2Both of them can be null depending the criteria selected on the search form.I don' want to use a dynamic querySo I can do something like:if @p1 is null and @p2 is nullselect ...else if @p1 is not null and @p2 is nullselect ... where p1=@p1 else if @p1 is null and @p2 is not nullselect ... where 2=@p2 else if @p1 is not null and @p2 is notnullselect ... where p1=@p1 and p2=@p2of course this is tediousIs there a way to do this with a single sql statement?" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-09 : 08:58:35
|
[code]select ...from ...where p1 = coalesce(@p1, p1)and p2 = coalesce(@p2, p2)[/code] KH |
 |
|
|
|
|
|