Lookup OR in Books Online, the help system for SQL Server. Also, look at the difference between IF, which conditionally runs statements, and CASE, which operates within a statement.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]