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 |
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2012-07-26 : 06:47:49
|
I've got two tables with the same fields like thisActive id Months CurrentNULL 2 7 true NULL 2 4 falseNULL 2 4 trueActive id Months Currenttrue 2 7 true true 2 4 falsefalse 2 4 trueIf need to update the active field in table one based on table two where the years/months/current fields matchThanks |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-26 : 06:52:44
|
Years?update t1set active = t2.activefrom table1 t1join table2 t2on t1.months = t2.monthsand t1.current = t2.currentwhere coalesce(t1.active,'') <> t2.active==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
vijayan.vinu3
Starting Member
19 Posts |
Posted - 2012-07-31 : 02:08:22
|
Try this:Update Ex1Set Active = b.Active From ( Select *, Row_Number() Over (Order By (Select NULL) ) As rn From Ex1 ) As a JOIN ( Select *, Row_Number() Over (Order By (Select NULL) ) As rn From Ex2 ) As b ON a.rn = b.rn |
 |
|
|
|
|