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 |
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2008-08-08 : 06:47:57
|
| Hi, I have this table with products and each product has a categoryid so:ProductID Product CategoryID1 Prod1 232 Prod2 413 Prod3 12I want to make a SP where I can say select * from productswhere categoryid = @categoryidOnly when I enter a -1 as categoryid it should doselect * form productsNow, I know you can do this with @categoryid int = -1and then something like:if @categoryid = -1 begin select * form products endelse begin select * from products where categoryid = @categoryid endBut I want to know an alternativeSince I want to add more parameters like this, and it becomes a bit of a mess then |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-08 : 06:50:36
|
[code]select * from productswhere categoryid = @categoryidor @categoryid = -1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2008-08-08 : 06:54:50
|
| Right, that was it....Thanks.The secret to creativity is knowing how to hide your sources. (Einstein) |
 |
|
|
|
|
|