=== modified file 'resources/sql/copydata.sql' --- resources/sql/copydata.sql 2011-03-19 22:37:57 +0000 +++ resources/sql/copydata.sql 2012-02-09 18:15:43 +0000 @@ -1,17 +1,28 @@ -- Move population data from last year to this year --- Replace first periodid with current year, replace second periodid with last year, replace dataset.name with population dataset name - -delete from datavalue where periodid=43668 and dataelementid in ( -select dataelementid from datasetmembers -join dataset using(datasetid) -where dataset.name='Population estimates' ); +-- If specific data level is required update the _orgunitstructure resource table + +-- Replace first periodid with current year, replace second periodid with last year, replace dataset.name with population dataset name, replace data level as required + +delete from datavalue where periodid=112482 and dataelementid in ( + select dataelementid from datasetmembers + join dataset using(datasetid) + where dataset.name='Population estimates' ) +and sourceid in ( + select os.organisationunitid from organisationunit ou + join _orgunitstructure os using(organisationunitid) + where os.level = 4); insert into datavalue(dataelementid,periodid,sourceid,categoryoptioncomboid,value,storedby,lastupdated,comment,followup) -select dataelementid,43668 as periodid,sourceid,categoryoptioncomboid,ceil(cast(value as double precision)*1.029) as value,storedby,lastupdated,comment,followup +select dataelementid,112482 as periodid,sourceid,categoryoptioncomboid,ceil(cast(value as double precision)*1.029) as value,storedby,lastupdated,null,false from datavalue -where periodid=21011 and dataelementid in ( -select dataelementid from datasetmembers -join dataset using(datasetid) -where dataset.name='Population estimates' ); +where periodid=43668 and dataelementid in ( + select dataelementid from datasetmembers + join dataset using(datasetid) + where dataset.name='Population estimates' ) +and sourceid in ( + select os.organisationunitid from organisationunit ou + join _orgunitstructure os using(organisationunitid) + where os.level = 4); +