Skip to content

Instantly share code, notes, and snippets.

@eoglethorpe
Created November 13, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eoglethorpe/5ef9d5db9f18f890c212 to your computer and use it in GitHub Desktop.
Save eoglethorpe/5ef9d5db9f18f890c212 to your computer and use it in GitHub Desktop.
--planned and neither date > delete (74)
delete from distributions
where act_desc in ('Tents', 'Tarpaulin','tarpaulin','Cash for Shelter (15,000 NPR)', 'CGI Bundle (72ft/bundle)')
and
act_status like 'Planned (funded)' and (start_dt is null and comp_dt is null)
--no status > delete (52)
delete from distributions
where act_desc in ('Tents', 'Tarpaulin','tarpaulin','Cash for Shelter (15,000 NPR)', 'CGI Bundle (72ft/bundle)')
and
act_status is null
--if no comp_dt but start_dt, set and vice versa
--blank start (434)
update distributions set
start_dt = comp_dt,
start_day = comp_day,
start_month = comp_month,
start_year = comp_year
where act_desc in ('Tents', 'Tarpaulin','tarpaulin','Cash for Shelter (15,000 NPR)', 'CGI Bundle (72ft/bundle)')
and start_dt is null and comp_dt is not null
--blank comp (113)
update distributions set
comp_dt = start_dt,
comp_day = start_day,
comp_month = start_month,
comp_year = start_year
where act_desc in ('Tents', 'Tarpaulin','tarpaulin','Cash for Shelter (15,000 NPR)', 'CGI Bundle (72ft/bundle)')
and start_dt is not null and comp_dt is null
--not a planned activity and blank date: set to as_of
--start date (508)
update distributions set
start_dt = as_of,
start_day = extract(day from to_date(as_of, 'DD/MM/YYYY')),
start_month = extract(month from to_date(as_of, 'DD/MM/YYYY')),
start_year = extract(year from to_date(as_of, 'DD/MM/YYYY'))
where act_desc in ('Tents', 'Tarpaulin','tarpaulin','Cash for Shelter (15,000 NPR)', 'CGI Bundle (72ft/bundle)')
and act_status not like 'Planned (funded)'
and start_dt is null
--comp date (508)
update distributions set
comp_dt = as_of,
comp_day = extract(day from to_date(as_of, 'DD/MM/YYYY')),
comp_month = extract(month from to_date(as_of, 'DD/MM/YYYY')),
comp_year = extract(year from to_date(as_of, 'DD/MM/YYYY'))
where act_desc in ('Tents', 'Tarpaulin','tarpaulin','Cash for Shelter (15,000 NPR)', 'CGI Bundle (72ft/bundle)')
and act_status not like 'Planned (funded)'
and comp_dt is null
--no VDC and ongoing/planned > delete (119)
delete from distributions
where vdc is null
and (act_status ilike '%ongoing%' or act_status ilike '%planned%')
@ZeeBhaby
Copy link

why did you use act_desc as a condition?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment