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 |
|
Sarah63777
Starting Member
8 Posts |
Posted - 2007-01-25 : 11:36:38
|
| I am trying to write a procedure in sql server. I am passing 4 parameters to this procedure and there is the possibility of each one being null.I was going to use the isNull funciton to work so that if the first parameter is null (which means they want everything returned for that column), then it will return everything. i need it to work like:where....and Reason=isNull(@Reason,*)but of course i'm getting an error. Is there a way to do this? |
|
|
Sarah63777
Starting Member
8 Posts |
Posted - 2007-01-25 : 11:54:08
|
| Or is there a way to append where clauses:ieIf firstParameter is not null thenwhere = where + 'and firstParameter = somecolumn'If secondParameter is not null thenwhere = where + 'and secondParameter = somecolumn2'.... |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2007-01-25 : 12:06:53
|
| Try thisWHERE (somecolumn = @param1 OR @param1 IS NULL) AND (somecolumn = @param2 OR @param2 IS NULL) AND (somecolumn = @param3 OR @param3 IS NULL) AND (somecolumn = @param4 OR @param4 IS NULL) |
 |
|
|
Sarah63777
Starting Member
8 Posts |
Posted - 2007-01-25 : 12:14:43
|
| wow thanks...I was making it way more complicated than it needed to be! thank-you that works! |
 |
|
|
|
|
|