moshe (yu******@gmail.com) writes:
I need an IF statment at SQL
I have 2 tables (names A B)
i need (In SQL stetments) to search from table A if rows in table B
with this conditions:
if B.col1=1 or B.col1=6 then search all row (1=1)
otherwise select A.col1=B.col1
this select is part of a big select from A,B tables
The CASE expression might be useful:
...
AND a.col1 = CASE WHEN b.col1 IN (1, 6) THEN b.col1 ELSE a.col1 END
...
If this does not cut it, you will get better help if you include more
information. The standard recommendatation is to include:
o CREATE TABLE statements for your tables (possibly simplified)
o INSERT statement with sample data.
o The desired result given the sample.
o A short description of the underlying business problem.
--
Erland Sommarskog, SQL Server MVP,
es****@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp