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 |
|
Steve33056
Starting Member
2 Posts |
Posted - 2010-02-23 : 11:39:18
|
| Hello,My name is Steve. This is a great resource and extremely valuable.Here is what I am trying to accomplish. I have a table with 3 subclaims. Policy SubClaim cStatus cPureClaimStatusCA-27979-0 CAFL0000000049 CL NULLCA-27979-0 CAFL0000000049 OP NULLCA-27979-0 CAFL0000000049 OP NULLI want to update all cPureClaimStatus of each subclaim to 'OP' if any cStatus value is 'OP' else cStatus = 'CL'. So in the case above I should have cPureClaimStatus = 'OP' for all 3 records even though one of the subclaims is CL for closed.End ResultPolicy SubClaim cStatus cPureClaimStatusCA-27979-0 CAFL0000000049 CL OPCA-27979-0 CAFL0000000049 OP OPCA-27979-0 CAFL0000000049 OP OPHow do I do this? Thanks in advance for your help. |
|
|
Steve33056
Starting Member
2 Posts |
Posted - 2010-02-23 : 11:41:13
|
| Hello Again,BTW, The subquery will be on the same table as these fields are in. There is no second table. The table name is tblMIS_CLM_ClaimInfoThanks again |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-23 : 12:12:55
|
| [code]UPDATE tSET t.cPureClaimStatus =CASE WHEN t1.StsCnt > 0 THEN 'OP' ELSE 'CL' ENDFROM Table tINNER JOIN (SELECT Policy, SubClaim, SUM(CASE WHEN cStatus='OP' THEN 1 ELSE 0 END) AS StsCnt FROM table GROUP BY Policy, SubClaim)t1ON t1.Policy = t.PolicyAND t1.SubClaim = t.SubClaim[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|