| Author |
Topic |
|
ramoneguru
Yak Posting Veteran
69 Posts |
Posted - 2007-06-11 : 20:15:12
|
| I need to update a single table based on the information from another table. Here's what I mean:insTable has 2 columns :newINS INToldINS INTAssessTable has 1 column:IDHere's my pseudo code:IF insTable.newINS <> insTable.oldINS THEN AssessTable.ID = insTable.newINSELSE do nothingIt may sound simple enough to do, but I can't figure it out. I'd rather not use a cursor either. Help!!--Nick |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-11 : 20:23:18
|
sample data and expected result please KH |
 |
|
|
ramoneguru
Yak Posting Veteran
69 Posts |
Posted - 2007-06-11 : 21:05:13
|
| Ok, like a few rows would look like this:insTable | AssessTableold new | ID---- ---- | ----------107 107 | 107107 107 | 107107 109 | 109107 109 | 109. . | .. . | .. . | .so if the old/new are different in the insTable then update the AssessTable with the newINS value. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-11 : 21:23:09
|
quote: IF insTable.newINS <> insTable.oldINSTHEN AssessTable.ID = insTable.newINS
You want to update AssessTable's ID to newINS ? What is the relationship between AssessTable and insTable ?is it AssessTable.ID = insTable.oldIns ? KH |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-12 : 00:06:02
|
| two table columns have duplicate entries... You have to normalise the table--------------------------------------------------S.Ahamed |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-12 : 09:14:04
|
| All you need is simple select. Do you need seperate table to have this?Select new from tablewhere old<>newMadhivananFailing to plan is Planning to fail |
 |
|
|
ramoneguru
Yak Posting Veteran
69 Posts |
Posted - 2007-06-12 : 16:27:37
|
| Ok, sorry for the lack of information. My fault, I mislabeled some things and it came out completely wrong. Let me start over.I have 1 table called AssessTable Primary Key is: IDI have a view called viewIns this view selects things from other irrelevant tables and the main things it selects are ID, newIns, and oldInsThe ID value in viewIns is the Primary Key in the AssessTable, so use that to link/update.Now, I need a way to look at the newIns and oldIns values in viewIns and compare them like this:IF (newIns <> oldIns)THEN update AssessTable SET AssessTable.ID = insView.newINS WHERE AssessTable.ID = viewIns.IDELSE do nothingexpected results:insTable | AssessTableold new | ID---- ---- | ----------107 107 | 107107 107 | 107107 109 | 109107 109 | 109. . | .. . | .. . | .--Nick |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-12 : 19:49:48
|
quote: IF (newIns <> oldIns)THEN update AssessTable SET AssessTable.ID = insView.newINS WHERE AssessTable.ID = viewIns.IDELSE do nothing
the viewIns.ID is newINS or oldINS ? KH |
 |
|
|
ramoneguru
Yak Posting Veteran
69 Posts |
Posted - 2007-06-13 : 15:20:38
|
| The viewIns.ID is the Primary Key in the AssessTable, namely AssessTable.IDso JOIN ON (viewIns.ID = AssessTable.ID)--Nick |
 |
|
|
dxsacjason
Starting Member
2 Posts |
Posted - 2007-06-14 : 15:07:11
|
| yak. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-14 : 21:08:42
|
actually you already got the query thereupdate aSET ID = i.newINS FROM AssessTable a INNER JOIN viewIns iON viewIns.ID = AssessTable.ID)WHERE i.newIns <> i.oldIns KH |
 |
|
|
dxsacjason
Starting Member
2 Posts |
Posted - 2007-06-19 : 18:25:39
|
quote: Originally posted by khtan actually you already got the query thereupdate aSET ID = i.newINS FROM AssessTable a INNER JOIN viewIns iON viewIns.ID = AssessTable.ID)WHERE i.newIns <> i.oldIns KH
Thank you khtan, that worked! |
 |
|
|
|