Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where clause condition help

Status
Not open for further replies.

itchyII

MIS
Apr 10, 2001
167
Hi All,
I am pretty new to SQL. I have a simple query, and I am trying to figure out how to add a condition to my where clause. The query looks something like this:

Code:
SELECT     tblItem.fldItemId, tblItem.fldInDate, tblItem.fldStartDate, tblItem.fldSchStart, tblItem.fldScopeId
FROM         tblItem

What I would like to add now is a condition in the WHERE clause that will select on those records based on something like:

if tblItem.fldScopeId = 1
then tblItem.fldInDate <> tblItem.fldSchStart
else tblItem.fldInDate <> tblItem.fldStartDate

It sounds simple, but I don't know the syntax!

Thank you in advance!
 
Code:
WHERE
  (tblItem.fldScopeId = 1 AND tblItem.fldInDate <> tblItem.fldSchStart) OR
  (tblItem.fldScopeId <> 1 AND 
else tblItem.fldInDate <> tblItem.fldStartDate)


or:
Code:
WHERE tblItem.fldInDate <> CASE WHEN tblItem.fldScopeId = 1
                                     THEN tblItem.fldSchStart
                                ELSE  tblItem.fldStartDate
                           END
not tested!!!!!!!!

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Grrrrrrrrrr.
Have typo in first example.
It should be:
Code:
WHERE
  (tblItem.fldScopeId = 1  AND tblItem.fldInDate <> tblItem.fldSchStart) OR
  (tblItem.fldScopeId <> 1 AND tblItem.fldInDate <> tblItem.fldStartDate)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top