Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jamie
Aged Yak Warrior
542 Posts |
Posted - 2004-03-10 : 07:12:42
|
| hello,I have 2 tables, customers and customers2.there is a link in customers2 to customers.IDIf that link exists how can I display the info. in one field for either the customers.name and the customers2.nameeg,customers tableID Name1 null2 bobcustomers2 tableID Name CID1 J1 1I want to display the info like nameJ1Bobhope that makes sense,thank for any help.Jamie |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-03-10 : 07:18:06
|
| SELECT a.Name FROM CUSTOMERS aWHERE EXISTS (SELECT b.* FROM CUSTOMERS2 b WHERE a.ID = b.ID)UNION ALLSELECT a.Name FROM CUSTOMERS2 aWHERE EXISTS (SELECT b.* FROM CUSTOMERS b WHERE a.ID = b.ID)--**** Something like thatDuane. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-03-10 : 07:53:01
|
| select ISNULL(a.name,b.name) as namefrom customers aleft outer join customers2 bon a.id = b.id- Jeff |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-03-10 : 07:58:52
|
| Nice!I misunderstood the original question, please ignore my first postDuane. |
 |
|
|
jamie
Aged Yak Warrior
542 Posts |
Posted - 2004-03-11 : 08:54:22
|
| thanks guys for the response.Jeff's post works correctly.thank you. |
 |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2004-03-11 : 09:16:51
|
Depending on your SQL version and performance you can also use:SELECT COALESCE(a.name,b.name) as nameFROM customers a LEFT OUTER JOIN customers2 b ON a.id = b.id |
 |
|
|
|
|
|