内部联接语句的SQL转换错误 - 不转换任何内容

时间:2016-11-01 15:31:11

标签: sql

我多年来一直使用这个网站进行研究,但无法从我的研究中找出这一点。得到以下错误:

  

转换varchar值时转换失败' 38221.0&#39>数据类型int。

这' 38221.0'与CP.DNCP_PATIENTID'相关联。从以下代码:

SELECT  PAT.V51_PRSNPERSONNUMBER AS PSNNMBR,
PAT.V51_PRSNFIRSTNAME AS FIRSTNAME,
PAT.V51_PRSNMIDDLENAME AS MIDDLENAME,
PAT.V51_PRSNLASTNAME AS LASTNAME,
ADDR.V8_PERSONHOMEADDRLINE1 AS ADDRESS,
ADDR.V8_PERSONHOMEADDRLINE2 AS ADDRESS2,
ADDR.V8_PERSONHOMEADDRCITY AS CITY,
ADDR.V8_PERSONHOMEADDRSTATE AS STATE,
ADDR.V8_PERSONHOMEADDRZIP AS ZIP,
PAT.V51_PRSNDOB AS DOB,
PAT.V51_PRSNSEX AS SEX,
PAT.V51_PRSNSSN AS SSN,
ADDR.V8_PERSONHOMEPHONENUMBER AS HOMEPHONE,
ADDR.V8_PERSONMOBILEPHONENUMBER AS MOBILEPHONE, 
CV.V9_DNPLANSORTNAME AS INSPLAN,
CV.V9_DNCARRIERNAME AS INSCARRIER,
COORD.PCCUSERNAME AS CARECOORDINATOR
FROM I_DNCHGSPMTS CP
LEFT OUTER JOIN IPROCEDURE PR
    ON (CP.DNCP_PROCEDURECODE = PR.PRPROCEDURECODE AND CP.OFFICE_ID = PR.OFFICE_ID)
LEFT OUTER JOIN I_VSTAFFCHGBILL STFBILL
    ON (CP.OFFICE_ID = STFBILL.OFFICE_ID AND CP.DNCP_PRACTICEID = STFBILL.V69_STPRACTICEID AND
        CP.DNCP_STAFFID_CREDITED = STFBILL.V69_STSTAFFID)
LEFT OUTER JOIN I_VPROVCHGBILL BILL
    ON (STFBILL.V69_STSTAFFID = BILL.V58_PROVPROVIDERID AND STFBILL.OFFICE_ID = BILL.OFFICE_ID)
LEFT OUTER JOIN I_DNCHGCOVERAGE CHGCV
    ON (CP.OFFICE_ID = CHGCV.OFFICE_ID AND CP.DNCP_CHARGESID = CHGCV.TPSCHARGESID)
LEFT OUTER JOIN I_VDNPLANCHGCV1 CV
    ON (CHGCV.CHGCVR1PLANID = CV.V9_DNPLANID AND CHGCV.OFFICE_ID = CV.OFFICE_ID)
LEFT OUTER JOIN I_VDEPTCHG DEP
    ON (CP.DNCP_DEPARTMENTCODE = DEP.V4_DPTDEPARTMENTCODE AND CP.OFFICE_ID = DEP.OFFICE_ID)
LEFT OUTER JOIN I_VDNADDRSPAT ADDR
    ON (CP.OFFICE_ID = ADDR.OFFICE_ID AND CP.DNCP_PATIENTID = ADDR.V8_TPSPERSONID)
LEFT OUTER JOIN I_VPERSONPAT PAT
    ON (CP.OFFICE_ID = PAT.OFFICE_ID AND CP.DNCP_PATIENTID = PAT.V51_PRSNPERSONID)
LEFT OUTER JOIN IACCOUNT ACC
    ON (CP.OFFICE_ID = ACC.OFFICE_ID AND CP.DNCP_ACCOUNTSID = ACC.ACCACCOUNTSID)
LEFT OUTER JOIN IPAYMENT PMT
    ON (CP.OFFICE_ID = PMT.OFFICE_ID AND CP.DNCP_PAYMENTSID = PMT.PMTPAYMENTSID)
LEFT OUTER JOIN I_VLUPROCCLASS CL
    ON (PR.OFFICE_ID = CL.OFFICE_ID AND PR.PRCLASS = CL.V85_LUCLOOKUPCODE)
LEFT OUTER JOIN I_VSVCCNTRPROC SVC
    ON (CP.OFFICE_ID = SVC.OFFICE_ID AND CP.DNCP_SERVICECENTERID = SVC.V75_SVCSERVICECENTERID)
LEFT OUTER JOIN I_DNDXPROCEVENT DX
    ON (CP.OFFICE_ID = DX.OFFICE_ID AND CP.DNCP_PROCEDUREEVENTSID = DX.TPSPROCEDUREEVENTSID)
LEFT OUTER JOIN IPATIENT IPAT
    ON (CP.OFFICE_ID = IPAT.OFFICE_ID AND CP.DNCP_PATIENTID = IPAT.PATDNPERSONNUMBER)
LEFT OUTER JOIN I_VPATCARECOORD COORD
    ON (IPAT.OFFICE_ID = COORD.OFFICE_ID AND IPAT.PATCARECOORDINATORID = COORD.PCCMMUSERSID)
INNER JOIN (
    SELECT  CP.DNCP_PATIENTID AS PSNNMBR,
        MAX(CP.DNCP_FROMSERVICEDATE) AS SVCDT
        --MIN(CP.DNCP_AMOUNT_CHARGE) AS CHGAMT
    FROM I_DNCHGSPMTS CP
        LEFT OUTER JOIN IPROCEDURE PR
            ON (CP.DNCP_PROCEDURECODE = PR.PRPROCEDURECODE AND CP.OFFICE_ID = PR.OFFICE_ID)
        LEFT OUTER JOIN I_VSTAFFCHGBILL STFBILL
            ON (CP.OFFICE_ID = STFBILL.OFFICE_ID AND CP.DNCP_PRACTICEID = STFBILL.V69_STPRACTICEID AND
            CP.DNCP_STAFFID_CREDITED = STFBILL.V69_STSTAFFID)
        LEFT OUTER JOIN I_VPROVCHGBILL BILL
            ON (STFBILL.V69_STSTAFFID = BILL.V58_PROVPROVIDERID AND STFBILL.OFFICE_ID = BILL.OFFICE_ID)
        LEFT OUTER JOIN I_DNCHGCOVERAGE CHGCV
            ON (CP.OFFICE_ID = CHGCV.OFFICE_ID AND CP.DNCP_CHARGESID = CHGCV.TPSCHARGESID)
        LEFT OUTER JOIN I_VDNPLANCHGCV1 CV
            ON (CHGCV.CHGCVR1PLANID = CV.V9_DNPLANID AND CHGCV.OFFICE_ID = CV.OFFICE_ID)
        LEFT OUTER JOIN I_VDEPTCHG DEP
            ON (CP.DNCP_DEPARTMENTCODE = DEP.V4_DPTDEPARTMENTCODE AND CP.OFFICE_ID = DEP.OFFICE_ID)
        LEFT OUTER JOIN I_VDNADDRSPAT ADDR
            ON (CP.OFFICE_ID = ADDR.OFFICE_ID AND CP.DNCP_PATIENTID = ADDR.V8_TPSPERSONID)
        LEFT OUTER JOIN I_VPERSONPAT PAT
            ON (CP.OFFICE_ID = PAT.OFFICE_ID AND CP.DNCP_PATIENTID = PAT.V51_PRSNPERSONID)
        LEFT OUTER JOIN IACCOUNT ACC
            ON (CP.OFFICE_ID = ACC.OFFICE_ID AND CP.DNCP_ACCOUNTSID = ACC.ACCACCOUNTSID)
        LEFT OUTER JOIN IPAYMENT PMT
            ON (CP.OFFICE_ID = PMT.OFFICE_ID AND CP.DNCP_PAYMENTSID = PMT.PMTPAYMENTSID)
        LEFT OUTER JOIN I_VLUPROCCLASS CL
            ON (PR.OFFICE_ID = CL.OFFICE_ID AND PR.PRCLASS = CL.V85_LUCLOOKUPCODE)
        LEFT OUTER JOIN I_VSVCCNTRPROC SVC
            ON (CP.OFFICE_ID = SVC.OFFICE_ID AND CP.DNCP_SERVICECENTERID = SVC.V75_SVCSERVICECENTERID)
        LEFT OUTER JOIN I_DNDXPROCEVENT DX
            ON (CP.OFFICE_ID = DX.OFFICE_ID AND CP.DNCP_PROCEDUREEVENTSID = DX.TPSPROCEDUREEVENTSID)
    WHERE CP.OFFICE_ID = 'EDQV'
        AND CP.DNCP_ACTIVITYTYPE = 'CHG'
        AND (CP.DNCP_PROCEDURECODE LIKE '99490' OR CP.DNCP_PROCEDURECODE LIKE 'CCM')
        AND (DATEDIFF(DAY,CP.DNCP_POSTDATE,GETDATE())) < 180
    GROUP BY CP.DNCP_PATIENTID
    ) AS MAXSVCDATE
    ON (CP.DNCP_PATIENTID = MAXSVCDATE.PSNNMBR AND CP.DNCP_FROMSERVICEDATE = MAXSVCDATE.SVCDT) --AND CP.DNCP_AMOUNT_CHARGE = MAXSVCDATE.CHGAMT)
WHERE CP.OFFICE_ID = 'EDQV'

由于我没有转换任何东西,我不确定为什么我会收到此错误。我在许多项目中使用了这种编码的变体,但从未收到错误。我感谢任何帮助。谢谢!

2 个答案:

答案 0 :(得分:1)

抱歉,我明白了。我以为它在我的INNER JOIN中,但它是在其他一个连接中。我加入了PERSONNUMBER到PERSONID。我修好了,现在一切顺利。一个案例,盯着它看太久,没有看到你面前的正确。谢谢你的时间。

答案 1 :(得分:0)

尝试CONV(N,from_base,to_base),它会在不同的数字基数之间转换数字。它返回一个转换后的数字N的字符串表示 从base_base到to_base