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 |
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2008-03-12 : 14:04:44
|
| Hey guys,Up to this point I've been dealing with mostly select statements but time has come, and I need to do an update. Basically I'm not sure how to structure the query.I'd like to update the field "new_applicationreceived" to the value of "new_lastcontact" based off the results of the following select query:select new_lastcontact from leadLEFT JOIN StringMap ON Lead.SalesStageCode = StringMap.AttributeValue AND StringMap.AttributeName = 'SalesStageCode' AND StringMap.ObjectTypeCode = 4where new_applicationreceived is nulland lead.salesstagecode = 5I'd really appreciate your help - I'm very worried about messing up the data and don't want to screw something up. |
|
|
tfountain
Constraint Violating Yak Guru
491 Posts |
Posted - 2008-03-12 : 14:46:42
|
quote: Originally posted by Skorch Hey guys,Up to this point I've been dealing with mostly select statements but time has come, and I need to do an update. Basically I'm not sure how to structure the query.I'd like to update the field "new_applicationreceived" to the value of "new_lastcontact" based off the results of the following select query:select new_lastcontact from leadLEFT JOIN StringMap ON Lead.SalesStageCode = StringMap.AttributeValue AND StringMap.AttributeName = 'SalesStageCode' AND StringMap.ObjectTypeCode = 4where new_applicationreceived is nulland lead.salesstagecode = 5I'd really appreciate your help - I'm very worried about messing up the data and don't want to screw something up.
UPDATE <alias>SET <column list>FROM <query> |
 |
|
|
NeilG
Aged Yak Warrior
530 Posts |
Posted - 2008-03-12 : 14:59:25
|
| UPDATE dbo.Table2 SET dbo.Table2.ColB = dbo.Table2.ColB + dbo.Table1.ColBFROM dbo.Table2 iNNER JOIN dbo.Table1 ON dbo.Table2.ColA = dbo.Table1.ColA |
 |
|
|
|
|
|