Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Johnny Gunn
Starting Member
5 Posts |
Posted - 2011-02-03 : 06:00:26
|
| I have a table TABLE_A with columns ID and VALUE and TABLE_B with ID and VALUE. For each row in TABLE_B where TABLE_B.ID = TABLE_A.ID I want TABLE_B.VALUE to be updated from TABLE_A.VALUE.I know this can be done with declaring a cursor and using loop but I don't know how to write it.Anyone that can help?regards Johnny Gunn |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-03 : 06:03:12
|
| Update Bset b.value=a.valuefrom table_A as A inner join table_B as Bon A.ID = B.IDMadhivananFailing to plan is Planning to fail |
 |
|
|
Johnny Gunn
Starting Member
5 Posts |
Posted - 2011-02-03 : 07:07:35
|
| Thanks, but I got error "Sql command not ended correctly" on the from keyword.The specific update:update tilsyn.etanlegg set a.hsikrfasetal = t.anleggnrfrom tmp_jgg_anleggfase as t inner join tilsyn.etanlegg as aon t.anleggnr = a.anleggnrHowever, this is working:select *from tmp_jgg_anleggfase t inner join tilsyn.etanlegg a on t.anleggnr = a.anleggnrJGregards Johnny Gunn |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-03 : 07:22:34
|
| What is this? tilsyn.etanlegg Just a table or Schema and a table or another DB's table |
 |
|
|
Johnny Gunn
Starting Member
5 Posts |
Posted - 2011-02-03 : 08:12:32
|
| It's schema and table.regards Johnny Gunn |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-03 : 08:24:58
|
| update tset a.hsikrfasetal = t.anleggnrfrom tmp_jgg_anleggfase as t inner join tilsyn.etanlegg as aon t.anleggnr = a.anleggnrJimEveryday I learn something that somebody else already knew |
 |
|
|
Johnny Gunn
Starting Member
5 Posts |
Posted - 2011-02-03 : 11:32:51
|
| Strange, but it doesn't work. I found some info on another forum where a person said that it works in Access but not in SQL. I think loop could solve it if anyone knows.Anyway, thanks for feedback.regards Johnny Gunn |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-04 : 04:39:56
|
quote: Originally posted by Johnny Gunn Strange, but it doesn't work. I found some info on another forum where a person said that it works in Access but not in SQL. I think loop could solve it if anyone knows.Anyway, thanks for feedback.regards Johnny Gunn
What did you mean by "It doesn't work"?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|