December 23, 2013 at 6:03 am
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??
Thanks,,
December 23, 2013 at 6:28 am
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.
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
January 3, 2014 at 2:56 pm
UPDATE x SET x.b = y.d
FROM TABLE1 x
JOIN table2 y ON x.a = y.c
January 3, 2014 at 8:42 pm
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.
@Gautham.gn,
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
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply