You are here: Re: Case Statement in Where Clause « MsSQL Server « IT news, forums, messages
Re: Case Statement in Where Clause

Posted by Ed Murphy on 10/13/06 02:11

Dan Guzman wrote:

> In SQL Server, CASE doesn't conditionally execute statements, it returns
> an expression. You might try something like:
>
> WHERE
> tblClient.companycode =
> CASE
> WHEN @myCompany = 933
> THEN 933 ELSE tblClient.companycode END
> AND
> tblCase.clientcode =
> CASE
> WHEN @myCompany <> 933
> THEN @myClient ELSE tblCase.clientcode END
> AND tblCase.status = 'Active'

Another alternative:

WHERE (NOT(@myCompany = 933) OR tblClient.companycode = 933)
AND (NOT(@myCompany <> 933) OR tblCase.clientcode = @myClient)
AND tblCase.status = 'Active'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация