From: Wilkinson, Jim <Jim.Wilkinson@cra-arc.gc.ca>
To: pgsql-sql@postgresql.org
Cc: Wilkinson, Jim <Jim.Wilkinson@cra-arc.gc.ca>
Subject: How too select different views using a IF/THEN/ELSE procedure ?
Date: Wed, 28 Mar 2007 15:04:30 -0400
Message-ID: <7CCC5BEF5E72394C963E529B54EB4A642A199E@SD01ITMV12.PROD.NET> (raw)
Below is a select statement that select incidents by month. I need a
function or a method to select differents views that will show the Month
columns is a different order. Say Apr - Mar for a fiscal year.
I need to do something like an if/then/else statement that selects the
correct view to use by a variable check.
Any ideas what I can use or do ?
select case public.incident.gender_code_id
WHEN 31 THEN 'Male'
WHEN 32 THEN 'Female'
ELSE 'Non-Person'
END,
count (case extract ( month from public.incident.incident_date
)WHEN 01 then 1 Else NULL END) as Jan,
count (case extract ( month from public.incident.incident_date
)WHEN 02 then 1 Else NULL END) as Feb,
count (case extract ( month from public.incident.incident_date
)WHEN 03 then 1 Else NULL END) as Mar,
count (case extract ( month from public.incident.incident_date
)WHEN 04 then 1 Else NULL END) as Apr,
count (case extract ( month from public.incident.incident_date
)WHEN 05 then 1 Else NULL END) as May,
count (case extract ( month from public.incident.incident_date
)WHEN 06 then 1 Else NULL END) as Jun,
count (case extract ( month from public.incident.incident_date
)WHEN 07 then 1 Else NULL END) as Jul,
count (case extract ( month from public.incident.incident_date
)WHEN 08 then 1 Else NULL END) as Aug,
count (case extract ( month from public.incident.incident_date
)WHEN 09 then 1 Else NULL END) as Sep,
count (case extract ( month from public.incident.incident_date
)WHEN 10 then 1 Else NULL END) as Oct,
count (case extract ( month from public.incident.incident_date
)WHEN 11 then 1 Else NULL END) as Nov,
count (case extract ( month from public.incident.incident_date
)WHEN 12 then 1 Else NULL END) as Dec,
count (extract ( month from public.incident.incident_date )) as
Total
from public.incident
GROUP BY public.incident.gender_code_id
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: Jim.Wilkinson@cra-arc.gc.ca
Subject: Re: How too select different views using a IF/THEN/ELSE procedure ?
In-Reply-To: <7CCC5BEF5E72394C963E529B54EB4A642A199E@SD01ITMV12.PROD.NET>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox