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 |
insideMyCity
Starting Member
2 Posts |
Posted - 2012-06-01 : 17:02:47
|
I have a queried results table where I need to take these results and update an individual row in two tables. For Example, Each table has a record that needs to be updated, each record has a field called InserviceID which is unique to each record. From the results table I am running an UPDATE WHERE statement saying if results.InserviceID = Table1.InserviceID then update the record with the new information.My problem is that even though the record is being updated, all of the other records in Table 1 are being changed to 'Null' value in that field.Any thoughts??Scott Aschenbrenner |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-01 : 23:46:04
|
quote: Originally posted by insideMyCity I have a queried results table where I need to take these results and update an individual row in two tables. For Example, Each table has a record that needs to be updated, each record has a field called InserviceID which is unique to each record. From the results table I am running an UPDATE WHERE statement saying if results.InserviceID = Table1.InserviceID then update the record with the new information.My problem is that even though the record is being updated, all of the other records in Table 1 are being changed to 'Null' value in that field.Any thoughts??Scott Aschenbrenner
actually you should not be adding this to where but you should be joining on itlikeUPDATE tSET t.Field = r.FieldFROM yourTable tJOIN Results r ON r.InserviceID = t.InserviceID this will make sure only records which are related to results will be affected by UPDATE operation------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|