From: | Darren Ferguson <darren(at)crystalballinc(dot)com> |
---|---|
To: | "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com> |
Cc: | postgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: mapping date value (SQL question) |
Date: | 2002-02-21 14:30:24 |
Message-ID: | Pine.LNX.4.10.10202210925010.15569-100000@thread.crystalballinc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
You have in plpgsql the ability to use IF THEN ELSIF ELSE
Also in pure SQL you can use the CASE WHEN THEN END
Example: Case Statement
CASE WHEN status = 1 THEN Draft
WHEN status = 2 THEN Open
WHEN status = 3 THEN Complete
WHEN status = 4 THEN Closed
ELSE undefined
End AS status
Example: PLPGSQL
IF subject = ''Location'' THEN
/* Code goes here */
ELSIF subject = ''Device'' THEN
/* Code goes here */
ELSE
/* Code goes here */
END IF;
Hope this helps
Darren Ferguson
On Thu, 21 Feb 2002, Johnson, Shaunn wrote:
> Howdy:
>
> I'm running Postgres 7.1.3 on RedHat Linux 7.2, kernel version
> 2.4.7 rel 10.
>
> I've created a table which includes the date. I have been instructed
> to map the date into something that reflects the quarter of the year
> on the fly (somewhere in the script). For example:
>
> (currently) date: (needed) quarter:
> 2001-02-26 200101
> 1998-05-12 199802
> 803-11-11 80304
>
> I was thinking I'd have to use something like a case statement, but
> I don't know enough about SQL to do something like that. Somehow, I
> had the notion that if it were possible to write 'if-then-else' loops
> I could probably do it.
>
> Is there such a mechanism to do what is being asked of me?
>
> Thanks!
>
> -X
>
From | Date | Subject | |
---|---|---|---|
Next Message | Johnson, Shaunn | 2002-02-21 14:31:43 | Re: mapping date value (SQL question) |
Previous Message | Greg Sabino Mullane | 2002-02-21 13:55:14 | Re: deleting an identical record |