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 |
|
anup23
Starting Member
19 Posts |
Posted - 2011-11-22 : 09:00:52
|
| I have two tables A and B .. and in that combination of three columns are uniquie , I have to update a row of table as 0 if the combination these columns doesnt match ..How can I write a query for this ...Could you plz help |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-22 : 09:16:16
|
| update tbl1set ---from tbl1 t1left join tbl2 t2on t1.col1 = t2.col1and t1.col2 = t2.col2and t1.col3 = t2.col3where t2.is null==========================================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. |
 |
|
|
anup23
Starting Member
19 Posts |
Posted - 2011-11-22 : 09:23:26
|
| thanks for the reply.. what if i need to set the value 0 when those 3 columns are not equal. |
 |
|
|
anup23
Starting Member
19 Posts |
Posted - 2011-11-22 : 09:32:01
|
| Just a doubt , y is this for???where t2.is null |
 |
|
|
anup23
Starting Member
19 Posts |
Posted - 2011-11-22 : 09:43:32
|
| I have two tables A and B .. and in that combination of three columns are uniquie , I have to update a column of table B as 0 if the combination these columns are not equal .How can I write a query for this ...Could you plz helpSorry I guess earlier,I didnt explained my question clearly ... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-22 : 10:04:38
|
quote: Originally posted by anup23 I have two tables A and B .. and in that combination of three columns are uniquie , I have to update a column of table B as 0 if the combination these columns are not equal .How can I write a query for this ...Could you plz helpSorry I guess earlier,I didnt explained my question clearly ...
That's what that statement does.Gets all the rows fro tbl1 which don't have a row matching in tbl2 on the three columns. Just complete the set clause to set the value to 0.The where clause is to restrict it to rows that don't match in the two tables.==========================================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. |
 |
|
|
|
|
|