January 27, 2011 at 5:19 pm
I need to update a column in table A, A.key, based on Table B, column B.Key, with value from table C, column C.key.
eg.
update
set A.key = C.key
where A.key in (select B.Key from A, B, C where A.key = B.key and C.date = B.date)
How can I do this? I am not really good at sql. It would be really helpful if someone can provide ms sql server 2008 syntax.
Thanks.
January 27, 2011 at 6:27 pm
do I have to write a stored procedure for this?
January 27, 2011 at 6:37 pm
applebutton (1/27/2011)
I need to update a column in table A, A.key, based on Table B, column B.Key, with value from table C, column C.key.eg.
update
set A.key = C.key
where A.key in (select B.Key from A, B, C where A.key = B.key and C.date = B.date)
How can I do this? I am not really good at sql. It would be really helpful if someone can provide ms sql server 2008 syntax.
Thanks.
You can need to use an inner join statement to update column A.Key based on the values from B.Key and C.Key.
-----------------------------
www.cbtr.net
.: SQL Backup Admin Tool[/url] :.
January 27, 2011 at 7:17 pm
Columns in table a are a.key
Columns in table b are b.key and b.date
Columns in table c are c.key and c.date
What I need to do is replace a.key with C.key values. I need to do lookup in B table based on b.key = a.key, then get the b.date corresponding to b.key. With b.date, I need to get C.key, based on b.date = c.date, then set a.key to C.key
How can I do this using update statement:
my update statement as follows:
update A
set A.key = C.key
from A inner join B on A.key = B.key inner join C on b.date = c.date
This is fine?
January 27, 2011 at 7:24 pm
are you looking to update based on any type of criteria as well?
if so, throw a WHERE a.key = "something" clause, otherwise, the update statement look good
-----------------------------
www.cbtr.net
.: SQL Backup Admin Tool[/url] :.
January 27, 2011 at 7:30 pm
Please read the first article I reference below in my signature block regarding asking for help. Follow those instructions in what you should post to get the best help possible. Be sure to also include the expected results based on the sample data you will have posted as well.
The more you do up front to help us, the more we can help you. In addition, you will get tested code in return.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply