You are here: Re: IF ELSE with WHERE, AND, OR « MsSQL Server « IT news, forums, messages
Re: IF ELSE with WHERE, AND, OR

Posted by Erland Sommarskog on 07/29/05 18:29

(jcochran@rethinkllc.com) writes:
> I appreciate everyones help on this.
>
> What if I wanted to add another parameter named @AccountID. AccountID
> is used to track who created the ticket. @AccountID would be set to
> NULL just like @SearchTerm is. I wanted to be able to check to see if
> either was passed in. Sometimes both will be; other times it will be
> either/or.
>...
> IF NOT @AccountID IS NULL THEN
> AND AccountID = @AccountID
> END IF

AND (AccountID = @AccountID OR @AccountID IS NULL)

However, beware that if you want any index on AccuontID to be use, you
better split this up and have two different SELECT statements.

For a much longer discussion on a problem which you have not really
reached, but seem to be on your way to, I have an article on my web
site that you can save for a rainy day:
http://www.sommarskog.se/dyn-search.html.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 

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

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