Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Updating a column in one table from another table Expand / Collapse
Posted Monday, December 23, 2013 6:03 AM


Group: General Forum Members
Last Login: Tuesday, February 3, 2015 5:28 AM
Points: 16, Visits: 86
We have two tables with names X and Y.
X has a,b columns. And Y has c,d columns.
I want to update b column in X table with the values from d column in Y table on condition X.a=Y.c.

Can u help me with this query??
Post #1525505
Posted Monday, December 23, 2013 6:28 AM



Group: General Forum Members
Last Login: Today @ 8:30 AM
Points: 7,897, Visits: 16,816
Check in Books Online for UPDATE, specifically UPDATE FROM. If you are still unsure, then take the time to read the posting etiquette article linked in my signature "please read this", and post DDL for your two tables with scripts to populate them with sample data.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1525518
Posted Friday, January 3, 2014 2:56 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, February 5, 2016 7:32 AM
Points: 649, Visits: 595
UPDATE x SET x.b = y.d
JOIN table2 y ON x.a = y.c
Post #1527736
Posted Friday, January 3, 2014 8:42 PM



Group: General Forum Members
Last Login: Today @ 10:20 AM
Points: 39,668, Visits: 36,800
Just to be clear, Chris was trying to get the OP to teach themselves how to answer such simple questions on their own instead of making them permanently dependent on the kindness of others on the web. Books Online is a very good tool for learning such basics and more. I'm amazed at how many people that are using SQL Server that don't even know what Books Online is.,

Two questions for you now that you have the coded answer to your question... 1) Do you understand all of the parts of that code and why it works and 2) do you know what Books Online actually is?

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Favorite Quotes:
"Has anyone ever told you that a query you have written runs too fast?" - Dwain Camps - 6 Mar 2014

Helpful Links:
How to post code problems
How to post performance problems
Post #1527772
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse