August 26, 2007 at 7:43 pm
Hi all
I have a customer table with a postcode and a suburb fields and cutomer info which is manually entered by data entry people...
I am trying to compare the entries against a postcode table with the correct postcodes which have fields postcode and suburb and based on the postcode entered in the customer table it should be the same as the suburb in the postcode table, if they are not the same output them to a table for manual checking..How would I go about this
thanks
August 26, 2007 at 11:00 pm
Something like this...
SELECT c.*,z.*
FROM Customer c
LEFT OUTER JOIN PostCodeTable z
ON c.PostCode = z.PostCode
AND c.Suburb = z.Suburb
WHERE z.PostCode IS NULL
--Jeff Moden
Change is inevitable... Change for the better is not.
August 27, 2007 at 8:19 am
Can you give us an idea of how you store these items in the tables? Jeff has a good suggestion, but it's hard to know if a left join is needed.
August 27, 2007 at 6:42 pm
Steve,
customer table consists off
customername varchar
customerphoneno varchar
postcode varchar
suburb varchar
The Postcode table is a table which I downloaded from the postoffice which contains all the valid postcodes in australia with postcode,locality in varchar
customer details are entered in manually with the postcode and surburb, i would like to compare the entries are correct based on the postcode with the suburb in the postcode table
Jeffs suggestion works btw but is there some other way ?
August 27, 2007 at 10:17 pm
There are, in fact, other ways using correlated subqueries in conjunction with IF EXISTS where, in the presence of correct indexes, can sometimes be made a bit faster than the outer join method I suggested. Sometimes, again, depending on the nature of the beast and the indexes present, WHERE NOT IN can be very fast as well.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply