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 |
cardgunner
326 Posts |
Posted - 2010-08-09 : 13:52:53
|
I trying to write a where clause in my sql statementdeclare @catg varchar(5)set @catg='MT004'select *from tblawhere case when @catg='' then tbla.t_ctg in ('MT005', 'ME004') else tbla.t_ctg=@catgWhat I'm trying to do is if there is a catg specified then run it with that catg if there is no catg specified then run it with the default catgs of MT005 and ME004. The error I get when I run it is "incorrect syntax near the keyword in"CardGunner |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-08-09 : 14:02:04
|
where ( @catg = '' and tbla.t_ctg in ('MT005', 'ME004') ) or tbla.t_ctg=@catgJimEveryday I learn something that somebody else already knew |
 |
|
cardgunner
326 Posts |
Posted - 2010-08-09 : 14:07:54
|
Yep works like a charm. Thank you very much!CardGunner |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-08-09 : 14:29:54
|
You're WelcomeJimEveryday I learn something that somebody else already knew |
 |
|
|
|
|