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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

case to determine which field from which table?

Status
Not open for further replies.
Jun 27, 2001
837
US
I have a select statement which needs to apply some logic to determine which fields to use. If the modify_timestamp = create_timestamp, then I want to use a location field from patient_medication table. If the modify_timestamp and create_timestamp are not equal, I need to use the location field from a location table. So my select would be
select account_id,ndc,startdate -- and then my logic. Am I correct that you can't use a case for this?
 
Code:
SELECT account_id,
       ndc,
       startdate,
       CASE WHEN modify_timestamp = create_timestamp THEN
                 patient_medication.Location
            ELSE 
                 Location.Location
            END AS Location
....

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
I'm not sure I understand what you're trying to do, but if I am understanding right, you have three tables you're selecting on. Assuming all of them are joined later in the select statement, would this work?

Code:
select
 account.account_id,
 account.ndc,
 account.startdate,
 case when account.modify_timestamp =    account.createtimestamp then patient_medication.location else location.location end as timestamp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top