domenica 16 settembre 2007

martedì 6 febbraio 2007

sql oracle update con select

1) Query per update veder in punto 2 la select relativa

-- residenza
update
anagrafe a
set
a.cod_oper_agg = 'CSI',
a.DATA_AGG = to_date('31 01 2007 12 01 01' , 'DD MM YYYY HH24 MI SS'),
a.usl_res = (select res.USSL from elenco_comuni res where res.ISTAT=a.COMUNE_RES) ,
a.REGIONE_RES = (select res.REGIONE from elenco_comuni res where res.ISTAT=a.COMUNE_RES)
where
((a.usl_res <> (select res.USSL from elenco_comuni res where res.ISTAT=a.COMUNE_RES and res.ussl <> '999')
and a.usl_res <> '999')
or
(a.REGIONE_RES <> (select res.REGIONE from elenco_comuni res where res.ISTAT=a.COMUNE_RES and res.regione <> '999')
and a.regione_res <> '999' ))
and
a.comune_res <> '777777' and a.cod_medico is null

2) select per controllo
-- 1) Query per controllo residenza
select
a.COMUNE_RES,
a.USL_RES,
(select res.USSL from elenco_comuni res where res.ISTAT=a.COMUNE_RES),
a.regione_res,
(select res.REGIONE from elenco_comuni res where res.ISTAT=a.COMUNE_RES),
a.*
from
anagrafe a
where
((a.usl_res <> (select res.USSL from elenco_comuni res where res.ISTAT=a.COMUNE_RES and res.ussl <> '999')
and a.usl_res <> '999')
or
(a.REGIONE_RES <> (select res.REGIONE from elenco_comuni res where res.ISTAT=a.COMUNE_RES and res.regione <> '999')
and a.regione_res <> '999' ))
and
a.comune_res <> '777777' and a.cod_medico is null
order by a.comune_res desc;

sql db2 as400

-- conta i record su as400 in base
SELECT P2DAP, P2STR, COUNT (*) FROM ugsd00/p2preno8
WHERE
P2DAP >
20060100 and p2dap < 20070299
and p2str LIKE 'LB800%'
GROUP BY P2DAP
, P2STR