Update table data in Database through linked server

  • I want to update my TableA on my ServerA by using linked server which is on serverB.I have successfully created the linked server but i am a little bit confused. Actually i have to update a columnA of TableA from the data coming from columnB(TableB) of linked server on the basis of the matched phoneNo in both of the tables. The confusion is that the phoneNo format coming from the linked server is in format "911234567891" and the phoneNo that are in my TableA is of format 123-456-7891. So i have to remove the 91 digit first then i have to convert this number into xxx-xxx-xxxx this format inorder to compare it with the column of TableA. I have written the following queries for changing the phone format and removing the 91 from start.

    SELECT

    [Phone Numbers]

    ,FORMAT([Phone Numbers],'###-###-####') AS [Formatted Phone]

    FROM tbl_sample

    UPDATE tbl_sample

    SET [Phone Numbers] = SUBSTRING([Phone Numbers], 3, 8000)

    WHERE [Phone Numbers] LIKE '91%'

    but i have no idea how i can can combine both of them in same query and then use it to update the data in TableA of serverA but the most frustrating thing is that i have to schedule this update after every 24 hours. Any kind of help/suggestion will be appreciated.

  • hope this help to solve your problem

    select stuff(stuff(SUBSTRING([phone number],3,10),4,0,'-'),8,0,'-') from tbl_sample

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply