Update table by selecting values from multiple tables sql -


i updating table values multiple tables.

update pv set             pv.[totaldintcg] = dr.tcgdcnt             ,pv.[avghba1cimprovement] = hsd.avghba1ccnt             ,pv.[totalchdintcg] = cpc.chdcnt             ,pv.[totalchdntcg] = cpd1.chdwithcholbpcnt             ,pv.[percentageofchdwithbpchol] = icp.chfelligpopul             ,pv.[totalcopdintcg] = copd.tcgcopdcount             ,pv.[totalcopdmrcpoxysatulevel] = copdmrc.totalcolevel             ,pv.[percentofertcg] = copdoxsatu.oxysatligpopu         #tmpetabel pv             inner join #dregistered dr             on  dr.sk_serviceproviderid = pv.sk_serviceproviderid                 , dr.years = pv.[reportyear]                 , dr.months = pv.[reportmonth]             inner join #hba1cscoredetails hsd             on  hsd.sk_serviceproviderid = pv.sk_serviceproviderid                 , hsd.years = pv.[reportyear]                 , hsd.months = pv.[reportmonth]             inner join #chdcount cpc             on  cpc.sk_serviceproviderid = pv.sk_serviceproviderid                 , cpc.years = pv.[reportyear]                 , cpc.months = pv.[reportmonth]             inner join #chdbpcholpatientsdetails cpd1             on  cpd1.sk_serviceproviderid = pv.sk_serviceproviderid                 , cpd1.years = pv.[reportyear]                 , cpd1.months = pv.[reportmonth]             inner join #improvementchfperpractice icp             on  icp.sk_serviceproviderid = pv.sk_serviceproviderid                 , icp.years = pv.[reportyear]                 , icp.months = pv.[reportmonth]             inner join #copdcount copd             on  copd.sk_serviceproviderid = pv.sk_serviceproviderid                 , copd.years = pv.[reportyear]                 , copd.months = pv.[reportmonth]             inner join #copddetailsmrcoxygensatulevel copdmrc             on  copdmrc.sk_serviceproviderid = pv.sk_serviceproviderid                 , copdmrc.years = pv.[reportyear]                 , copdmrc.months = pv.[reportmonth]             inner join #improvperelligpopula copdoxsatu             on  copdoxsatu.sk_serviceproviderid = pv.sk_serviceproviderid                 , copdoxsatu.years = pv.[reportyear]                 , copdoxsatu.months = pv.[reportmonth] 

the issue here , tables have many rows , have less rows. getting less rows every table after update

should use update separably each select table..

assuming columns updating in pv nullable should ensure capture relevant data:

update pv set         pv.[totaldintcg] = dr.tcgdcnt         ,pv.[avghba1cimprovement] = hsd.avghba1ccnt         ,pv.[totalchdintcg] = cpc.chdcnt         ,pv.[totalchdntcg] = cpd1.chdwithcholbpcnt         ,pv.[percentageofchdwithbpchol] = icp.chfelligpopul         ,pv.[totalcopdintcg] = copd.tcgcopdcount         ,pv.[totalcopdmrcpoxysatulevel] = copdmrc.totalcolevel         ,pv.[percentofertcg] = copdoxsatu.oxysatligpopu     #tmpetabel pv         left join #dregistered dr         on  dr.sk_serviceproviderid = pv.sk_serviceproviderid             , dr.years = pv.[reportyear]             , dr.months = pv.[reportmonth]         left join #hba1cscoredetails hsd         on  hsd.sk_serviceproviderid = pv.sk_serviceproviderid             , hsd.years = pv.[reportyear]             , hsd.months = pv.[reportmonth]         left join #chdcount cpc         on  cpc.sk_serviceproviderid = pv.sk_serviceproviderid             , cpc.years = pv.[reportyear]             , cpc.months = pv.[reportmonth]         left join #chdbpcholpatientsdetails cpd1         on  cpd1.sk_serviceproviderid = pv.sk_serviceproviderid             , cpd1.years = pv.[reportyear]             , cpd1.months = pv.[reportmonth]         left join #improvementchfperpractice icp         on  icp.sk_serviceproviderid = pv.sk_serviceproviderid             , icp.years = pv.[reportyear]             , icp.months = pv.[reportmonth]         left join #copdcount copd         on  copd.sk_serviceproviderid = pv.sk_serviceproviderid             , copd.years = pv.[reportyear]             , copd.months = pv.[reportmonth]         left join #copddetailsmrcoxygensatulevel copdmrc         on  copdmrc.sk_serviceproviderid = pv.sk_serviceproviderid             , copdmrc.years = pv.[reportyear]             , copdmrc.months = pv.[reportmonth]         left join #improvperelligpopula copdoxsatu         on  copdoxsatu.sk_serviceproviderid = pv.sk_serviceproviderid             , copdoxsatu.years = pv.[reportyear]             , copdoxsatu.months = pv.[reportmonth] 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -