SQL Update command getting more than expected -


i'm trying update on sql db (2008 r2), reason it's updating more expected. think there's issue where, join, , update commands i'm having trouble finding info on scope , order of operations. fortunately, i'm practicing on db backups restored before make change in production one!

i've found this link seems similar (join , update), it's tough me apply case.

for testunitcount of 15578, i'm trying change unitno 05101 05088. reason, it's moving unitno of them testnumber. it's olap db (cubes), may seem more complicated tables people used to. thought had command correct time:

select     dashboarddata.testnumber, testunits.unitno, testunitcounts.testunitcount         dashboarddata inner join                       testunitcounts on dashboarddata.testunitcountid = testunitcounts.testunitcountid inner join                       measurementdata on testunitcounts.testunitcountid = measurementdata.testunitcountid inner join                       testunits on dashboarddata.testunitid = testunits.testunitid , testunitcounts.testunitid = testunits.testunitid ,                        measurementdata.testunitid = testunits.testunitid                       unitno='05101'                       , testnumber='1024'                       , testunitcounts.testunitcount='15578'                       order testunitcount asc                       update testunits                       set unitno='05088' unitno='05101' 

does know command needs changed change testunitcount of 15578 unitno 05101->05088 test 1024? why changing of them testnumber?

here cte attempt same thing. i'm getting 0 row(s) affected when execute it:

use olap05132014c go   queryname_cte (unitno,testnumber,testunitcount) ( select     dashboarddata.testnumber, testunits.unitno, testunitcounts.testunitcount         dashboarddata inner join                       testunitcounts on dashboarddata.testunitcountid = testunitcounts.testunitcountid inner join                       measurementdata on testunitcounts.testunitcountid = measurementdata.testunitcountid inner join                       testunits on dashboarddata.testunitid = testunits.testunitid , testunitcounts.testunitid = testunits.testunitid ,                        measurementdata.testunitid = testunits.testunitid                       unitno='05101'                       , testnumber='1024'                       , testunitcounts.testunitcount='15578' ) update queryname_cte                         set unitno='05088' unitno='05101' 

as stated in comment above, update being run seperately. change query update instead of select.

change query -

    update testunits     set testunits.unitno = '05088'             dashboarddata inner join                           testunitcounts on dashboarddata.testunitcountid = testunitcounts.testunitcountid inner join                           measurementdata on testunitcounts.testunitcountid = measurementdata.testunitcountid inner join                           testunits on dashboarddata.testunitid = testunits.testunitid , testunitcounts.testunitid = testunits.testunitid ,                            measurementdata.testunitid = testunits.testunitid                           unitno='05101'                           , testnumber='1024'                           , testunitcounts.testunitcount='15578'                           order testunitcount asc 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -