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

Condiditonal SQL?

Status
Not open for further replies.

jchastai

Programmer
Oct 11, 2001
31
US
I have a standard SELECT SQL statement in which one of the items in the table is a field called Owner. The owner field can either be an id number that points off to another table called users -OR- it coule be a persons name, email address.

Now what I need to return in a single query is the Owner's Name in one field and the Owner's Email address in a second.

Is there a way to do a conditional
if Owner is numeric
pull owner name from users AS OwnerName
pull owner email from users AS OwnerEmail
else
first item in Onwer AS OwnerName
second item in Owner AS OwnerEmail
end

?????

Any help would be appreciated - thanks!
-- Jeff
 
Hi jchastai,

could you give a description of the table and a sample value for the columns with and without the numeric id?

I need to understand more before I write the SQL

Thanks
 
You could try using a UNION of 2 SELECTs. I just did this in a SQL Server DB and it worked great.

The 1st select would grab only the id records. The 2nd select would grab the non id records.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top