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!

using case to select duplicate named fields from joined tables

Status
Not open for further replies.

tmartin99

MIS
Joined
Sep 14, 2001
Messages
9
Location
US
I have two tables that I'm joining using left outer joins that have duplicate fields, but I only want to output these fields in one output field.

example;

select
c.field_name,
name_out =
case when a.name is not null then a.name
when b.name is not null then b.name
end
from
table_name c
left outer join
table_name a
on c.id = a.id
left outer join
table_name b
on c.id = b.id

Is this correct logic and does anyone see any problem with it?
 

I would add an ELSE to the CASE statement for completeness.

case when a.name is not null then a.name
when b.name is not null then b.name
Else '' Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top