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 |
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-02-21 : 14:14:00
|
| Hi i have a select statement which if the parameter @SubCatID = 0 then i need this where clauseWHERE St_Cat_ID = @SubCatID AND@StockCode LIKE '%' + @Code + '%'else i need this where clauseWHERE St_Cat_ID = @SubCatID AND @StockCode LIKE '%' + @Code + '%'how do i go about doing this |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-02-21 : 15:47:55
|
| I'm confused. Both WHERE clauses look the same to me...? |
 |
|
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-02-21 : 15:55:50
|
| o yes sorryif @SubCatID = 0 thenWHERE StockCode LIKE '%' + @Code + '%'else i need this where clauseWHERE St_Cat_ID = @SubCatID AND StockCode LIKE '%' + @Code + '%' |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-02-21 : 16:05:42
|
If St_Cat_ID's are not equal to 0 then you can do something like this:WHERE (@SubCatID = 0 OR St_Cat_ID = @SubCatID) AND StockCode LIKE '%' + @Code + '%' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-22 : 01:08:24
|
| More points on the samewww.sommarskog.se/dyn-search.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|