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 |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2010-12-17 : 08:59:14
|
| Hi AllIam trying to replace the column values in a table based on two other columns in the same tableSample DataClaimNo LineNo Flag Procedurecode100 01 N MN4567100 02 Y 7863100 03 N MN8976100 04 Y 9000101 01 Y 8954101 02 N MN6754101 03 N MN7654101 04 Y 8976 102 01 Y 1234102 02 Y 2345102 03 Y 3456102 03 Y 4567Every ClaimNo column has multiple rows of data.But if procedurecode column for a claimNo starts with MN then all the associated values with the claimno for the flag column should change to NSo the data should become like belowClaimNo LineNo Flag Procedurecode100 01 N MN4567100 02 N 7863100 03 N MN8976100 04 N 9000101 01 N 8954101 02 N MN6754101 03 N MN7654101 04 N 8976 102 01 Y 1234102 02 Y 2345102 03 Y 3456102 03 Y 4567 |
|
|
lazycoder
Starting Member
12 Posts |
Posted - 2010-12-17 : 10:24:56
|
You can use this:update thetable set Flag = 'N'from (SELECT ClaimNo FROM thetable WHERE LEFT(Procedurecode, 2) = 'MN') as tmpwhere thetable.ClaimNo = tmp.ClaimNo AND thetable.Flag = 'Y' But you should consider restructuring your tables if you need to do this regularly.-----------------http://it.expertmonster.com/ |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-01-10 : 22:26:23
|
| Is there any other way than temp table logic as i need to use the same logic in another reporting tool (BO)Thanks |
 |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-01-11 : 00:58:58
|
| try this:update table tablename set column='Y' where procedurecode like 'MN%' |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-01-11 : 09:00:32
|
| Update table is not going to help me in this case because Iam not trying to update the table data but based on the data want to create a report |
 |
|
|
|
|
|