Saturday 15 March 2014

sql server 2005 - SQL update by inner join -


Say I have two tables and want to update the records in t1 only for those records which are present in T2 Are there.

  id = int, all other varchar t1 id & lt; PK & gt; Sample, Variables, Status, Notes T2 Sample, Variable   

I can select subset from T1 to join T2

  sample from t1 INNER Select t2. Sample = t2. Sample and t1 Variable = t2.Variable   

But what is it syntax to convert to an update statement that does not pull the update value from T2? (My values ​​do not get T2; T2 only limits that record which should be updated to the record.)

  UPDATE T1 SET status = N'Complete ', Notes = Notes of Ann Notes' INNER JOIN T2 ON T1. Sample = T2. Sample and T1 Variable = T2. The variable    

You have almost acquired it: < Code> update t1Aliased SET status = N'Complete ', notes = notes of notes' t1 t1Aliased join the INNER t1Aliased.Nample = t2.Sample on t1 and t1Aliased.Variable = t2.Variable

No comments:

Post a Comment