top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

SQL update from one Table to another based on a ID match

+3 votes
85 views

This is the Sales_Import table, where the account number field needs to be updated:
LeadID AccountNumber

147 5807811235 
150 5807811326 
185 7006100100007267039

And this is the RetrieveAccountNumber table, where I need to update from:
LeadID AccountNumber

147 7006100100007266957 
150 7006100100007267039 
posted Jun 19, 2015 by Manikandan J

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote
 
Best answer
DECLARE @TB1 TABLE
        (
            No Int
            ,Name NVarchar(50)
        )

        DECLARE @TB2 TABLE
        (
            No Int
            ,Name NVarchar(50)
        )

        INSERT INTO @TB1 VALUES(1,'asdf');
        INSERT INTO @TB1 VALUES(2,'awerq');


        INSERT INTO @TB2 VALUES(1,';oiup');
        INSERT INTO @TB2 VALUES(2,'lkjhj');

        SELECT * FROM @TB1

        UPDATE @TB1 SET Name =S.Name
        FROM @TB1 T
        INNER JOIN @TB2 S
                ON S.No = T.No

        SELECT * FROM @TB1
answer Jun 22, 2015 by Shivaranjini
Similar Questions
+2 votes

I want to update data from one table to another table with year condition.
(OR)
To Update one table based on another table using INNER JOIN

+3 votes

I have a table that looks something like this:

SetId ID Premium 
2012 5 Y 
2012 6 Y 
2013 5 N 
2013 6 N

I want to update the 2013 records with the premium values where the setid equals 2012.
So after the query it would look like this:

SetId ID Premium 
2012 5 Y
 2012 6 Y 
2013 5 Y 
2013 6 Y

Any help greatly appreciated

+1 vote

How to copy a table from one to another table in sql?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...