Link to home
Start Free TrialLog in
Avatar of ezzadin
ezzadin

asked on

Need help with an update statement

Hi,

I have tableA that contains calling prefix and rates, ie
23555,0.025
2354,0.005
123332,0.32


and tableB that contain phone number ie
23555222123123
23541334342
12333253444

I need to update tableB and set tableB.Rate = tableA.Rates. so basically depending on the prefix I have to set the rate on tableB.

So tableB should look like this:

23555222123123,0.025
23541334342,0.005
12333253444,0.32


How can I do this?

Thanks.
Avatar of dsacker
dsacker
Flag of United States of America image

Are these separate columns in your table, or one column with data delimited by a comma?
Assuming we have tableA: prefix, rate  and tableB: phone, rate:
update b
set rate = A.Rate
from tableB B join tableA A on A.prefix = left(B.Phone, length(A.Prefix))

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of edtechdba
edtechdba
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ezzadin
ezzadin

ASKER

Thanks .. it worked.