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 |
rajajuliana
Starting Member
4 Posts |
Posted - 2008-11-07 : 05:03:24
|
hi.. i got a prob with my script..i want to join 3 tables to get supplier info. below is the script.SELECT a.OrgnName, c.OrgnId, b.FirstName, c.ContactMode, c.ContactAddFROM Organisation a, Person b, PersonContact cWHERE a.orgnid = c.orgnid AND b.personid = c.personidand this is the output.OrgnName | OrgnId |FirstName | ContactMode | ContactAdd JULIE CO. 333-555 JULIE WORKPHONE 12345678JULIE CO. 333-555 JULIE WORKFAX 87654321JULIE CO. 333-555 JULIE EMAIL julie@julie.comMARY GROUP 222-444 MARY WORKPHONE 65432112MARY GROUP 222-444 MARY WORKFAX 34567543MARY GROUP 222-444 MARY EMAIL mary@mary.combut, i don't want output like this because the data is duplicate in the first 3 columns. i manage to solve this problem by using this script (using CASE : row into column) but only from one table (PersonContact)select orgnid, min(case when ContactMode = 'WORKPHONE' then ContactAdd else NULL end) as WorkPhone, min(case when ContactMode = 'WORKFAX' then ContactAdd else NULL end) as WorkFax, min(case when contactMode = 'EMAIL' then ContactAdd else NULL end) as Emailfrom PersonContactgroup by orgnidand the output became like thisOrgnId | WorkPhone | WorkFax | Email333-555 12345678 87654321 julie@julie.com222-444 65432112 34567543 mary@mary.comthe problem is, i failed to join the 3 tables (Organisation, Person, PersonContact) in that script to get the output as belowOrgnName | OrgId | FirstName | WOrkPhone | WorkFax | EmailJULIE CO. 333-555 JULIE 12345678 87654321 julie@julie.comMARY GROUP 222-444 MARY 65432112 34567543 mary@mary.comi hope somebody can help me..thanks in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 05:26:30
|
[code]SELECT a.OrgnName, a.OrgnId,tmp.FirstName,tmp.WorkPhone,tmp.WorkFax,tmp.EmailFROMOrganisation aINNER JOIN (select c.orgnid,c.FirstName,min(case when c.ContactMode = 'WORKPHONE' then c.ContactAdd else NULL end) as WorkPhone,min(case when c.ContactMode = 'WORKFAX' then c.ContactAdd else NULL end) as WorkFax,min(case when c.contactMode = 'EMAIL' then c.ContactAdd else NULL end) as Emailfrom PersonContact cINNER JOIN Person bON b.personid = c.personidgroup by c.orgnid,c.FirstName)tmpON a.orgnid = tmp.orgnid[/code] |
|
|
|
|
|
|
|