I have the following query. I need an output which would look like this
ea_month case ea_year zone_id
January 0 2013 4001
February 0 2013 4002
March 1 2013 4001
January 0 2014 4001
February 0 2014 4001
March 1 2014 4001
February 0 2014 4002
March 1 2014 4002
SELECT ea_month,CASE WHEN ea_month = (SELECT to_char(now(), 'Month')) THEN 1 ELSE 0 END,ea_year,zone_id FROM staging_ea.stg_circle_zone_billedamount_rollup
In my table I have my values for ea_month in the form of January, February, March.
After running the above query, the result-set that I am getting is something like this:
ea_month case ea_year zone_id
January 0 2013 4001
February 0 2013 4002
March 0 2013 4001
January 0 2014 4001
February 0 2014 4001
March 0 2014 4001
February 0 2014 4002
March 0 2014 4002
Can anyone suggest me where am I going wrong? Its for a PostgreSQL query.
CASEstatement.case when ea_month = to_char(now(), 'Month') then ...should do it. Of course that is subject to environment settings: the name of the month returned by theto_char()function depends on the locale settings of the current user.to_char()actually returns'January'in English and not in some other language? What doesSELECT to_char(now(), 'Month')return on its own?