如何在现有的sql查询中使用bitwise运算符?

时间:2016-03-09 11:14:15

标签: sql sql-server

这是我的SQL查询。我在索赔表中有列名“ExpenseBucketCoverage”,我在其中存储按位运算符,将多个值存储在一列中,如下所示

MED_COPAY = 1, MED_DED= 10, MED_COINS = 100, RX_COPAY = 1, RX_DED= 10, RX_COINS = 100

我想替换MED_COPAYMED_COINSMED_DEDRX_DEDRX_COINS&等硬编码值。查询中RX_COPAY使用ExpenseBucketCoverage列值。有人可以告诉我该怎么做?

有人建议我在灵魂之下

  

从声明中检索数据并离开加入资格中的第一个匹配记录。然后添加自定义代码以循环遍历数据行以按行覆盖的费用桶拆分行,并根据索赔的ExpenseBucketCoverage值在内存列中设置服务类别代码。

SELECT 
e.categoryid,
c.servicetype,
'II' AS RepordType, 
e.TPAId AS TPA_Id,
e.EmployerCode,
e.SubscriberId,
e.MemberID,
c.ServiceFrom,
c.ServiceTo,  
CASE 
    WHEN e.categoryid IN( 'MED_DED', 'RX_DED' ) THEN 
        deductible 
    WHEN e.categoryid IN( 'MED_COINS', 'RX_COINS' ) THEN 
        isnull(coins,0) 
    WHEN e.categoryid IN( 'MED_COPAY', 'RX_COPAY' ) THEN 
        copay 
        ELSE 0
        END AS ClaimAmount,  
'' AS AccountTypeCode, 
'1' ClaimsCrossoverAutoPay, 
e.CategoryId,   
    CASE c.ServiceType 
        WHEN 'H' THEN 
            CASE e.PayeeIndicator 
                WHEN 'N' THEN '0' 
                WHEN 'Y' THEN '1' 
        END 
        WHEN 'P' THEN '0' 
        END AS PayProvider,  
    CASE c.ServiceType 
        WHEN 'H' THEN 
        CASE PayeeIndicator 
            WHEN 'N' THEN '0' 
            WHEN 'Y' THEN '1' 
            END 

        WHEN 'P' THEN '0' 
            END AS ReimbursementMethod,  

    CASE c.ServiceType 
        WHEN 'H' THEN c.Provider 
        WHEN 'P' THEN '' 
        END AS ProviderId,  
'1' EnforceAccountEffectiveDates, 
c.Id, 
c.ClaimNumber + e.CategoryId as 'ExternalClaimNumber', 
c.ProviderName, 
c.CarrierId + ';' + c.SourceClaimNumber AS Notes  
FROM Claim c   
INNER JOIN Eligibility e   ON e.TPAId = c.TPAId AND e.EIN = c.EIN AND  
 c.Processed = 'Y' AND e.FilterType = 'Eligibility'  
 AND c.TPAId='PrimePay'  
 AND (c.ServiceFrom   >= e.BenefitEffectiveDate 
 AND c.ServiceFrom           <=e.BenefitTermDate)   
 AND (  (  c.PayorID = c.PatientSSN
 AND e.SubscriberSSN = c.PatientSSN   
 AND (c.EmployeeFirstName = c.PatientFirstName 
 AND c.EmployeeLastName = c.PatientLastName)  
 AND(e.MemberSSN = '' OR e.MemberSSN = NULL)  
 AND(e.MemberFirstName = '' OR e.MemberFirstName = NULL)
 AND(e.MemberLastName = '' OR e.MemberLastName = NULL))
 OR((c.PayorID !=  c.PatientSSN AND e.MemberSSN = c.PatientSSN 
 AND  e.MemberFirstName = c.PatientFirstName 
 AND e.MemberLastName = c.PatientLastName)  
 OR(c.PayorID != c.PatientSSN AND e.MemberFirstName = c.PatientFirstName 
 AND e.MemberLastName= c.PatientLastName)))
 AND (( c.Servicetype ='P' 
 AND e.CategoryID IN('RX_COINS','RX_COPAY', 'RX_DED' )) 
 OR ( c.Servicetype = 'H' 
 AND e.CategoryID IN( 'MED_COINS','MED_COPAY', 'MED_DED' ))) 

0 个答案:

没有答案