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.
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.
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))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks .. it worked.