从XML提取数据时复制条目

时间:2019-02-26 16:51:15

标签: sql-server xml

我已经使用下面的代码从存储在其中的XML格式提取数据,并加入多个表以获取所需的信息。

with fulldata as(
    SELECT
        WoundVisitType = vvaf.Data.value('(//WoundVisitType_GroupBox/@Label)[1]', 'varchar(max)'),      
        InitialOnset = vvaf.Data.value('(//HS_Initial_Onset_DateBox/@Value)[1]', 'varchar(max)'),
        VenArtWnds = vvaf.Data.value('(//WT_ArtVenWnds_PrmTextBox/@Value)[1]', 'varchar(2)'),
        AddendumNotes = vvaf.Data.value('(//AddendumNotes_TextBox/@Value)[1]', 'varchar(max)'),
        Addendum = vvaf.Data.value('(//Addendum_CheckBox/@Value)[1]', 'varchar(max)'),
        AddendumDate = vvaf.Data.value('(//Addendum_DateBox/@Value)[1]', 'varchar(12)'),
        Hospice = vvaf.Data.value('(//Hospice_CheckBox/@Value)[1]', 'varchar(5)'),
        WoundType = vvaf.Data.value('(//WoundType_GroupBox/@Label)[1]', 'varchar(max)'),
        WoundLocation = vvaf.Data.value('(//LocWnd_Find/@Value)[1]', 'varchar(max)'),
        OtherLocation = vvaf.Data.value('(//Wound_Loc_Other_Text/@Value)[1]', 'varchar(max)'),
        PIStage = vvaf.Data.value('(//PI_STAGE_GroupBox/@Value)[1]', 'varchar(max)'),
        HealingStatus = vvaf.Data.value('(//HEALSTATUS_GroupBox/@Label)[1]','varchar(max)'),
        DepthTissueInvol = vvaf.Data.value('(//DepthTissueInvolvement_GroupBox/@Label)[1]', 'varchar(max)'),
        ReopenRiskPoorIntake = vvaf.Data.value('(//OWT_Comorb_PoorIntake_Checkbox/@Value)[1]', 'varchar(5)'),
        ReopenRiskDiabetes = vvaf.Data.value('(//OWT_Comorb_Diabetes_Checkbox/@Value)[1]', 'varchar(5)'),
        ReopenRiskIncontinence = vvaf.Data.value('(//OWT_Comorb_Incontinence_Checkbox/@Value)[1]', 'varchar(5)'),
        ReopenRiskLimMob = vvaf.Data.value('(//OWT_Comorb_Immobility_Checkbox/@Value)[1]', 'varchar(5)'),
        ReopenRiskOther = vvaf.Data.value('(//OWT_Comorb_Other_Check/@Value)[1]', 'varchar(5)'), 
        ReopenRiskOtherDX = vvaf.Data.value('(//OWT_Comorb_Other_Text/@Value)[1]', 'varchar(max)'),
        NoncomplianceDressing = vvaf.Data.value('(//OWT_Wound_Compliance_DressingChanges_CheckBox/@Value)[1]', 'varchar(5)'),
        NoncomplianceHygiene = vvaf.Data.value('(//OWT_Wound_Compliance_Hygiene_CheckBox/@Value)[1]', 'varchar(5)'),
        NoncomplianceNutrition = vvaf.Data.value('(//OWT_Wound_Compliance_Nutrition_CheckBox/@Value)[1]', 'varchar(5)'),
        NoncomplianceOffloading = vvaf.Data.value('(//OWT_Wound_Compliance_Offloading_CheckBox/@Value)[1]', 'varchar(5)'), 
        NoncompliancePeriCare = vvaf.Data.value('(//OWT_Wound_Compliance_PeriCare_CheckBox/@Value)[1]', 'varchar(5)'),
        NoncomplianceRepositioning = vvaf.Data.value('(//OWT_Wound_Compliance_Repositioning_CheckBox/@Value)[1]', 'varchar(5)'),
        NoncomplianceOther = vvaf.Data.value('(//OWT_Wound_Compliance_Other_CheckBox/@Value)[1]', 'varchar(5)'),
        NoncomplianceOtherReason = vvaf.Data.value('(//OWT_Wound_Compliance_Other_TextBox/@Value)[1]', 'varchar(max)'),
        ILength = vvaf.Data.value('(//Wound_Measurement_Length_TextBox/@Value)[1]', 'varchar(max)'),
        IWidth = vvaf.Data.value('(//Wound_Measurement_Width_TextBox/@Value)[1]', 'varchar(max)'),
        IDepth = vvaf.Data.value('(//Wound_Measurement_Depth_TextBox/@Value)[1]', 'varchar(max)'),
        TunnelLength = vvaf.Data.value('(//OWT_Tunnel_Lth_PrmTextBox/@Value)[1]', 'varchar(max)'),
        TunnelDirection = vvaf.Data.value('(//OWT_Tunnel_Clock_PrmTextBox/@Value)[1]', 'varchar(max)'),
        UnderminingDirection1 = vvaf.Data.value('(//OWN_UND_FROM_PrmTextBox/@Value)[1]', 'varchar(max)'),
        UnderminingDirection2 = vvaf.Data.value('(//OWT_UND_TO_PrmTextBox/@Value)[1]', 'varchar(max)'),
        UnderminingDepth = vvaf.Data.value('(//OWT_Under_Deep_PrmTextBox/@Value)[1]', 'varchar(max)'),
        Epithelial = vvaf.Data.value('(//OWT_FT_Epithelial_TextBox/@Value)[1]', 'varchar(max)'),
        Granulation = vvaf.Data.value('(//OWT_FT_Granulation_TextBox/@Value)[1]', 'varchar(max)'),
        Slough = vvaf.Data.value('(//OWT_FT_Slough_TextBox/@Value)[1]', 'varchar(max)'),
        Eschar = vvaf.Data.value('(//OWT_FT_Eschar_PrmTextBox/@Value)[1]', 'varchar(max)'),
        Periwound = vvaf.Data.value('(//Wound_PERIWOUND_GroupBox/@Label)[1]', 'varchar(max)'),
        Exudate = vvaf.Data.value('(//Wound_EXUDATE_GroupBox/@Label)[1]', 'varchar(max)'),  
        SSI_None = vvaf.Data.value('(//OWT_Infec_None_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        SSI_Warmth = vvaf.Data.value('(//OWT_Infec_Warm_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        SSI_Erythema = vvaf.Data.value('(//OWT_Infec_Ery_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        SSI_Odor = vvaf.Data.value('(//OWT_Infec_Odor_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        SSI_Purulence = vvaf.Data.value('(//OWT_Infec_Puru_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        SD_SubQ = vvaf.Data.value('(//OWT_TisLev_Subq_CheckBox/@Value)[1]', 'varchar(5)'),
        SD_Fascia = vvaf.Data.value('(//OWT_TisLev_Fascia_CheckBox/@Value)[1]', 'varchar(5)'),
        SD_Tendon = vvaf.Data.value('(//OWT_TisLev_Tendon_CheckBox/@Value)[1]', 'varchar(5)'),
        SD_Muscle = vvaf.Data.value('(//OWT_TisLev_Muscle_CheckBox/@Value)[1]', 'varchar(5)'),
        SD_Bone = vvaf.Data.value('(//OWT_TisLev_Bone_CheckBox/@Value)[1]', 'varchar(5)'),
        Mat_Removed_Slough = vvaf.Data.value('(//OWT_MatRem_slough_checkbox/@Value)[1]', 'varchar(5)'),
        Mat_Removed_Eschar = vvaf.Data.value('(//OWT_MatRem_eschar_checkbox/@Value)[1]', 'varchar(5)'),
        Mat_Removed_Other = vvaf.Data.value('(//OWT_MatRem_other_CheckBox/@Value)[1]', 'varchar(5)'),
        Mat_Removed_Other_Text = vvaf.Data.value('(//OWT_MatRem_other_TextBox/@Value)[1]', 'varchar(max)'),
        Slough_Remaining = vvaf.Data.value('(//PWT_PostDeb_Slough_PrmTextBox/@Value)[1]', 'varchar(4)'),
        Eschar_Remaining = vvaf.Data.value('(//PWT_PostDeb_Eschar_PrmTextBox/@Value)[1]', 'varchar(4)'),
        ReviewedAntiCoag = vvaf.Data.value('(//ShpDebrid_AntiCoagulant_CheckBox/@Value)[1]', 'varchar(5)'),
        SharpDeb_CLEARALL = vvaf.Data.value('(//SharpDebride_ClearAll_CheckBox/@Value)[1]', 'varchar(5)'),
        PostDeb_Length = vvaf.Data.value('(//PWT_PostDeb_Length_PrmTextBox/@Value)[1]', 'varchar(5)'),
        PostDeb_Width = vvaf.Data.value('(//PWT_PostDeb_Width_PrmTextBox/@Value)[1]', 'varchar(5)'),
        PostDeb_Depth = vvaf.Data.value('(//PWT_PostDeb_Depth_PrmTextBox/@Value)[1]', 'varchar(5)'),
        ChemDeb = vvaf.Data.value('(//OWT_SharpDeb_OtherProc_Checkbox/@Value)[1]', 'varchar(5)'),
        Pared_Callous = vvaf.Data.value('(//OWT_SharpDeb_Callous_Checkbox/@Value)[1]', 'varchar(5)'),
        Number_Callous_Lesion = vvaf.Data.value('(//PWT_PostDeb_NumCallous_PrmTextBox/@Value)[1]', 'varchar(2)'),
        Incision_Drainage = vvaf.Data.value('(//PWT_PostDeb_ID_Checkbox/@Value)[1]', 'varchar(5)'),
        Number_InD_Lesions = vvaf.Data.value('(//PWT_PostDeb_NumID_PrmTextBox/@Value)[1]', 'varchar(2)'),   
        TissueBiopsy = vvaf.Data.value('(//OWT_SharpDeb_Biopsy_Checkbox/@Value)[1]', 'varchar(5)'),
        Number_Biopsy_Lesions = vvaf.Data.value('(//PWT_PostDeb_NumBiopsy_PrmTextBox/@Value)[1]', 'varchar(2)'),
        OtherProc = vvaf.Data.value('(//PWT_PostDeb_Other_Checkbox/@Value)[1]', 'varchar(5)'),
        OtherProcType =vvaf.Data.value('(//PrmTextBox1PWT_PostDeb_OtherProc_PrmTextBox/@Value)[1]', 'varchar(max)'),
        Tolerance = vvaf.Data.value('(//ShpDebrid_TOLERANCE_GroupBox/@Label)[1]', 'varchar(max)'),
        PainControl_Insensate = vvaf.Data.value('(//OWT_PainCTRL_Insen_CheckBox3/@Value)[1]', 'varchar(5)'),
        PainControl_Premed = vvaf.Data.value('(//OWT_PainCTRL_premed_CheckBox3/@Value)[1]', 'varchar(5)'),
        PainControl_Benzo = vvaf.Data.value('(//OWT_PainCTRL_Benzo_CheckBox3/@Value)[1]', 'varchar(5)'),
        Curette = vvaf.Data.value('(//OWT_Instrum_Curette_CheckBox/@Value)[1]', 'varchar(5)'),
        Scalpel = vvaf.Data.value('(//OWT_Instrum_Scalpel_CheckBox/@Value)[1]', 'varchar(5)'),
        Scissors = vvaf.Data.value('(//OWT_Instrum_Scissors_CheckBox/@Value)[1]', 'varchar(5)'),
        Forceps = vvaf.Data.value('(//OWT_Instrum_Forceps_CheckBox/@Value)[1]', 'varchar(5)'),
        DebNotes =vvaf.Data.value('(//ShpDebrid_ADDL_DEBRIDE_NOTES_Notes/@Value)[1]', 'varchar(max)'),  
        MASD_SkinBarrier = vvaf.Data.value('(//Tx_MASD_PtThk_SkinProtect_CheckBox/@Value)[1]', 'varchar(5)'),
        MASD_ZincAF = vvaf.Data.value('(//Tx_MASD_PtThk_ZincAntifung_CheckBox/@Value)[1]', 'varchar(5)'),
        MASD_Zinc20 = vvaf.Data.value('(//Tx_MASD_PtThk_Zinc_CheckBox/@Value)[1]', 'varchar(5)'),
        MASD_AFPowder = vvaf.Data.value('(//Tx_MASD_PtThk_AFPowder_CheckBox/@Value)[1]', 'varchar(5)'), 
        BarrierWipe_Spray = vvaf.Data.value('(//Tx_MPDH_barrierwipe_CheckBox/@Value)[1]', 'varchar(5)'),
        UnnaBoot = vvaf.Data.value('(//Tx_Venous_UNNA_CheckBox4/@Value)[1]', 'varchar(5)'),
        UnnaByProvider = vvaf.Data.value('(//Tx_Venous_UnnaApplied_CheckBox/@Value)[1]', 'varchar(5)'),
        UnnaChange = vvaf.Data.value('(//Tx_Venous_UNNA_PrmTextBox/@Value)[1]', 'varchar(2)'),
        ACEWrap = vvaf.Data.value('(//Tx_Venous_ACE_CheckBox/@Value)[1]', 'varchar(5)'),
        Tubigrip = vvaf.Data.value('(//Tx_Venous_TUBI_CheckBox/@Value)[1]', 'varchar(5)'),
        TEDHose = vvaf.Data.value('(//Tx_Venous_TED_CheckBox/@Value)[1]', 'varchar(5)'),
        TXFrequency = vvaf.Data.value('(//Days_TextBox/@Value)[1]', 'varchar(2)'),
        Hydrogel = vvaf.Data.value('(//Tx_MPDH_WndGelCheckBox/@Value)[1]', 'varchar(5)'),
        HydrogelAG = vvaf.Data.value('(//Tx_MPDH_WndGel_AG_PrmCheckBox/@Value)[1]', 'varchar(5)'),          
        MedHoney = vvaf.Data.value('(//Tx_MPDH_MedHoney_CheckBox/@Value)[1]', 'varchar(5)'),
        MedHoneyAG = vvaf.Data.value('(//Tx_MPDH_MedHoney_AG_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        Xeroform = vvaf.Data.value('(//Tx_MPDH_Xeroform_CheckBox/@Value)[1]', 'varchar(5)'),
        HydrogelGauze = vvaf.Data.value('(//Tx_MPDH_HydrogelGauze_CheckBox/@Value)[1]', 'varchar(5)'),
        HydrogelGuazeAG = vvaf.Data.value('(//Tx_MPDH_HydrogelGauze_AG_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        OilEmulsion = vvaf.Data.value('(//Tx_MPDH_OilEmuls_CheckBox/@Value)[1]', 'varchar(5)'),
        Collagen = vvaf.Data.value('(//Tx_DND_Collagen_CheckBox/@Value)[1]', 'varchar(5)'), 
        Collagen_Type = vvaf.Data.value('(//Tx_DND_Collagen_Type_TextBox/@Value)[1]', 'varchar(max)'),
        NaClGuaze = vvaf.Data.value('(//Tx_DND_SodChlGz_CheckBox/@Value)[1]', 'varchar(5)'),
        Alginate = vvaf.Data.value('(//Tx_DND_Alginate_CheckBox/@Value)[1]', 'varchar(5)'),
        AlginateAG=vvaf.Data.value('(//Tx_DND_Alginate_AG_CheckBox/@Value)[1]', 'varchar(5)'),
        Hydrofiber = vvaf.Data.value('(//Tx_DND_Hydrofiber_CheckBox/@Value)[1]', 'varchar(5)'), 
        HyydrofiberAG = vvaf.Data.value('(//Tx_DND_Hydrofiber_AG_CheckBox/@Value)[1]', 'varchar(5)'),
        WoundGelDressing = vvaf.Data.value('(//WoundGel_DressingOptions/@Label)[1]', 'varchar(max)'),
        Humifiber = vvaf.Data.value('(//Tx_DND_Humifiber_CheckBox/@Value)[1]', 'varchar(5)'),   
        HydroferaBlue = vvaf.Data.value('(//TxOpt_Venous_HydroferaBlue_CheckBox/@Value)[1]', 'varchar(5)'), 
        SpecializedFoam = vvaf.Data.value('(//TxOpt_MPDH_SpecFoam_CheckBox/@Value)[1]', 'varchar(5)'),
        SpecializedFoamType = vvaf.Data.value('(//TxOpt_MPDH_SpecFoam_Type_TextBox/@Value)[1]', 'varchar(5)'),
        ADBPad = vvaf.Data.value('(//Tx_MPDH_ABDPad_CheckBox/@Value)[1]', 'varchar(5)'),
        Hydrocolloid = vvaf.Data.value('(//Tx_MPDH_hydrocoloid_CheckBox/@Value)[1]', 'varchar(5)'),
        AdFilm = vvaf.Data.value('(//Tx_MPDH_AdhFilmlCheckBox /@Value)[1]', 'varchar(5)'),
        Santyl = vvaf.Data.value('(//Tx_ENZYME_SANTYLCheckBox/@Value)[1]', 'varchar(5)'),
        Antimicrobial = vvaf.Data.value('(//TxOpt_INFECT_GroupBox/@Label)[1]', 'varchar(max)'), 
        AntimicroFreq = vvaf.Data.value('(//TX_INFECT_Blue_Days_Text/@Value)[1]', 'varchar(2)'),
        AntiMocrobInst  = vvaf.Data.value('(//TX_INFECT__Iodine_TextBox/@Value)[1]', 'varchar(max)'),
        PHMBNotes = vvaf.Data.value('(//TxOpt_PHMB_Text_Note/@Value)[1]', 'varchar(max)'),
        NegPress = vvaf.Data.value('(//Tx_MASD_PtThk__NEGPres_CheckBox/@Value)[1]', 'varchar(max)'),
        mmHgcont = vvaf.Data.value('(//Tx_MASD_PtThk_NegPres_mmHG_TextBox/@Value)[1]', 'varchar(2)'),
        NegPressDays = vvaf.Data.value('(//Tx_MASD_PtThk_Days_GroupBox/@Label)[1]', 'varchar(max)'),
        AltTx = vvaf.Data.value('(//ALTTX_Other_CheckBox/@Value)[1]', 'varchar(5)'),
        AltTxNotes = vvaf.Data.value('(//ALTTX_Other_Note/@Value)[1]', 'varchar(5)'),
        ALtTxDays = vvaf.Data.value('(//ALTTX_Other_DAYS_TextBox/@Value)[1]', 'varchar(5)'),
        AirMattress = vvaf.Data.value('(//PVWM_Mattress_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        AirMattressText = vvaf.Data.value('(//PVWM_Mattress_PrmTextBox/@Value)[1]', 'varchar(max)'),
        ChairCushion = vvaf.Data.value('(//PVWM_Chair_PrmCheckBox/@Value)[1]','varchar(5)'), 
        CushionType = vvaf.Data.value('(//PVWM_Chair_Type_GroupBox/@Label)[1]', 'varchar(max)'),
        PTOTConsult = vvaf.Data.value('(//PVWM_PTOT_PrmCheckBox/@Value)[1]', 'varchar(5)'),
        PTOTLocation = vvaf.Data.value('(//PVWM_PTOT_Location_TextBox/@Value)[1]', 'varchar(max)'),
        AddNotes = vvaf.Data.value('(//Additional_Orders_Note/@Value)[1]', 'varchar(max)'), 
        TimeComponent = vvaf.Data.value('(//TimeComponentCheckBox/@Value)[1]', 'varchar(5)'),
        FollowUp = vvaf.Data.value('(//FollowUp_GroupBox/@Label)[1]', 'varchar(max)'),                  
        DOS = v.VisitDate,
        v.ProviderUid, 
        v.RenderingProviderUid,
        ServiceSiteUid_v = v.ServiceSiteUid, 
        lss.ServiceSiteUid, 
        lss.Name,
        v.PatientUid,
        per.PersonUid,
        per.FirstName, 
        per.LastName,
        per.BirthDate, 
        ProviderUid_p = prov.ProviderUid, 
        ProviderName = prov.Name
   FROM VisitAssessmentForm vvaf
   INNER JOIN Visit v ON v.VisitUid = vvaf.VisitUid
   INNER JOIN ListServiceSite lss ON lss.ServiceSiteUid = v.ServiceSiteUid
   INNER JOIN Person per ON per.PersonUid = v.PatientUid
   INNER JOIN ProviderCpp prov ON prov.ProviderUid = v.ProviderUid
   )
   SELECT *
   FROM fulldata
   WHERE DOS = '20190218' AND ProviderName = 'John' ;

由于某种原因,查询生成的每个条目都重复72次或重复72次。我是SQL的新手,正在这里进行实时学习,但是重复是由于代码中的某些错误引起的吗?

我曾尝试过故障排除,但我真的不知道哪里出了问题。

1 个答案:

答案 0 :(得分:0)

在第2行中使用SELECT DISTINCT而不是“ SELECT”修复了该错误。