Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.databases.postgresql > #365
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Harry Tuttle <OTPXDAJCSJVU@spammotel.com> |
| Newsgroups | comp.databases.postgresql |
| Subject | Re: (sql beginner) help for request |
| Date | Thu, 21 Jun 2012 08:44:41 +0200 |
| Lines | 28 |
| Message-ID | <a4fu76FqdjU1@mid.individual.net> (permalink) |
| References | <4fe22af0$0$6485$426a74cc@news.free.fr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net 08D8P7vjuB5nkAIx2Lp3NQO9pMXw7WjNAH81qJAbUyjFX8bDdSmraa3p2EO2iKEm8= |
| Cancel-Lock | sha1:tK6k0jMhLbWbKJgo54XAjErJviU= |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
| In-Reply-To | <4fe22af0$0$6485$426a74cc@news.free.fr> |
| Xref | csiph.com comp.databases.postgresql:365 |
Show key headers only | View raw
meta, 20.06.2012 21:56:
> Hi
>
> I know postgresql but not enough to solve the following problem:
>
> Here is a table with the fields: name char(20), c1 char(1), c2 char (1)
>
> The goal is to concat these fields after transformation in order to display them on one ligne:
> - c1 and c2 values are Y or N. If 'Y' it will be replaced by 'A', if 'N' it will be replaced by 'B'.
> - name must have 20 characters even if its lenght is less than 20, in order to align the results properly
>
> For example, here are two records: ('apple','Y','N') and ('cranberry','N','N')
>
> Final display wished:
> apple A B
> cranberry B B
>
> But I don't know how in the same request to concat fields, add a number of spaces at the end of name depending of its length and replace one value by another one...
>
> Thanks for any help.
>
select rpad(name, 20, ' ')||
case when c1 = 'Y' then 'A' else 'B' end||
case when c2 = 'Y' then 'A' else 'B' end
from the_table
Back to comp.databases.postgresql | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
(sql beginner) help for request "meta" <xyz@abc.fr> - 2012-06-20 21:56 +0200
Re: (sql beginner) help for request Stuart McGraw <smcg4191@frii.com> - 2012-06-20 16:09 -0600
Re: (sql beginner) help for request Stuart McGraw <smcg4191@frii.com> - 2012-06-20 16:31 -0600
Re: (sql beginner) help for request Harry Tuttle <OTPXDAJCSJVU@spammotel.com> - 2012-06-21 08:44 +0200
Re: (sql beginner) help for request Jasen Betts <jasen@xnet.co.nz> - 2012-06-21 07:59 +0000
Re: (sql beginner) help for request "meta" <xyz@abc.fr> - 2012-06-22 23:46 +0200
csiph-web