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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 PostalCodes Splitting

Author  Topic 

asarak
Starting Member

36 Posts

Posted - 2005-10-25 : 01:26:59
Hi guys,

I want to know if there is another way to include all data
even if pTail field is null and only the pHeader is the same with
the first 3 digits from PostalCode


select
r.Suraname,
r.Fname,
r.JobDesc,
r.Address,
r.Town,
isnull(p.Area,'-'),
isnull(p.Region,'-'),
r.PostalCode
from Ranks as r
left outer join Regions as p on p.pHeader=left(r.PostalCode,3) and p.pTail is null
group by ...
order by ...


The tables have the following data

Ranks
Surname Fname JobDesc Address Town PostalCode
GATES BILL IT STREET 13 NEW YORK 123 45
SUTTER HERB IT STREET 14 NEW YORK 123
HUWE MARIE MD STREET 1334 LONDON 441
BLOOM DOMINIK DF STREET 432 LONDON 442
SOLARI SANTIAGO IT STREET 1245 LONDON 442 00
COREL JOHN MD STREET 456 MANCHESTER 857 15

and

Regions
Area Region pHeader pTail
PRIME LONDON 441 NULL
PRIME LONDON 442 00
SECOND MANCHESTER 857 NULL
OUTLAND NEW YORK 123 NULL
OUTLAND NEW YORK 123 41
OUTLAND NEW YORK 123 42
OUTLAND NEW YORK 123 43
OUTLAND NEW YORK 123 44
OUTLAND NEW YORK 123 45


Regards
ASARAK

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-25 : 01:33:45
What do you get from that query?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

asarak
Starting Member

36 Posts

Posted - 2005-10-25 : 01:51:37
I just want to get all the data from Ranks and the Area and Region from Regions when i check the PostalCode to be in the proper Area.
For Example,

Ranks
Surname Fname JobDesc Address Town PostalCode
GATES BILL IT STREET 13 NEW YORK 123 45
SUTTER HERB IT STREET 14 NEW YORK 123
HUWE MARIE MD STREET 1334 LONDON 441
BLOOM DOMINIK DF STREET 432 LONDON 442
SOLARI SANTIAGO IT STREET 1245 LONDON 442 00
COREL JOHN MD STREET 456 MANCHESTER 857 15

and

Regions
Area Region pHeader pTail
PRIME1 LONDON 441 NULL
PRIME2 LONDON 442 00
SECOND MANCHESTER 857 NULL
OUTLAND1 NEW YORK 123 NULL
OUTLAND2 NEW YORK 123 41
OUTLAND3 NEW YORK 123 42
OUTLAND4 NEW YORK 123 43
OUTLAND5 NEW YORK 123 44
OUTLAND6 NEW YORK 123 45



Name Surname..Town - Area - Region - PostalCode
Bill - Gates - New York - OUTLAND6 - NEW YORK - 123 45
Solari-Santiago-London - PRIME 2 - LONDON - 442 00

Do i make it clear??
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-25 : 04:04:37
I asked you what your query returns

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

asarak
Starting Member

36 Posts

Posted - 2005-10-25 : 07:08:42
this is the output...

BLOOM DOMINIK DF STREET 432 LONDON - - 442
COREL JOHN MD STREET 456 MANCHESTER SECOND MANCHESTER 857 15
GATES BILL IT STREET 13 NEW YORK OUTLAND NEW YORK 123 45
HUWE MARIE MD STREET 1334 LONDON PRIME1 LONDON 441
SOLARI SANTIAGO IT STREET 1245 LONDON - - 442 00
SUTTER HERB IT STREET 14 NEW YORK OUTLAND NEW YORK 123
Go to Top of Page
   

- Advertisement -