0

So ive found ive got a list of addresses (street, suburb, postcode) and added them into a table tmp_addresses. My idea was to split up the current addresses that are all in one line using the following code:

UPDATE  Client
SET     ClientCity = t.Suburb
FROM    tmp_Addresses t
WHERE   ClientAddress LIKE '%' + t.Street + '%' + t.suburb + '%'

UPDATE  Client
SET     ClientPostcode= t.postcode
FROM    tmp_Addresses t
WHERE   ClientAddress LIKE '%' + t.Street + '%' + t.suburb + '%'

UPDATE  Client
SET     ClientAddress2 = ClientAddress

UPDATE  Client
SET     ClientAddress = LEFT(ClientAddress, 3) + ' ' + t.Street
FROM    tmp_Addresses t
WHERE   ClientAddress LIKE '%' + t.Street + '%' + t.suburb + '%'

This does work, however it is unbelievably slow, i ran it for around 30 minutes and got 2 results when i searched for suburbs that are not null. Any ideas on how i can speed this up? Initially i tried using:

UPDATE  Client
SET     ClientCity = t.Suburb
        ,ClientPostcode = t.Postcode
        ,ClientAddress = LEFT(ClientAddress, 3) + ' ' + t.Street
FROM    tmp_Addresses t
WHERE   ClientAddress LIKE '%' + t.Street + '%' + t.suburb + '%'

But i kept getting errors saying ClientPostcode does not exist, not sure why. Either way the above would still take a very long time.

EDIT::

The second section of code now works:

UPDATE  Client
SET     ClientCity = t.Suburb
        ,ClientPostcode = t.Postcode
        ,ClientAddress = LEFT(ClientAddress, 3) + ' ' + t.Street
FROM    tmp_Addresses t
WHERE   ClientAddress LIKE '%' + t.Street + '%' + t.suburb + '%'

However it is still incredibly slow and is using 98% of the CPU.

Owain Esau
  • 1,876
  • 2
  • 21
  • 34
  • Could you copy and paste the error message please? – McNets Feb 07 '17 at 22:04
  • Hi, it seems to be working when i run it now, not sure what i did wrong with that but either way it is still very slow. – Owain Esau Feb 07 '17 at 22:07
  • 2
    Even if you add an index on ClientAdress, it cannot be used with like % http://stackoverflow.com/a/1395881/3270427 – McNets Feb 07 '17 at 22:11
  • If you have a lot of records and a disk that is slow -- updating every record is going to be slow index or no. – Hogan Feb 07 '17 at 22:23
  • Ive been unable to index the column, so ive been limiting it down to ranges to see how long it would take. For 1000 records it took half an hour, since this needs to be done on 298k records its not very feasible. Plus the disk usage on the server its running on is at 100% whilst this is happening :S – Owain Esau Feb 08 '17 at 01:45
  • can't you make this a one-off task so speed is of no concern, and store future records according to your multi column layout? – Cee McSharpface Feb 08 '17 at 08:51
  • Could you post som example data? – CruelIO Feb 08 '17 at 14:39

0 Answers0