Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Harry Tuttle Newsgroups: comp.databases.postgresql Subject: Re: (sql beginner) help for request Date: Thu, 21 Jun 2012 08:44:41 +0200 Lines: 28 Message-ID: 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 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