MySQL Forums
Forum List  »  Newbie

if() query help needed
Posted by: lan w
Date: February 12, 2009 10:43AM

Hi,
I'm trying to concat few database string together with recursive if() query.
here is the data in the table Y:
Id Awardscode1 Awardamount1 Awardcode2 Awardamount2 Awardcode3 Awardamount3
1 aa 10 bb 20 cc 30
2 0 0 0

I want output for Id 1 as
aa:10/bb:20/cc:30
and for Id 2, nothing should be shown.

so I tried the following query:
select if(`Awardcode3`='',if(`Awardcode2`='',if(`Awardcode1`='','',concat(`Awardcode1`, ':', `Awardamount1`)) as award1, concat(award1, '/', (`Awardcode2`, ':', `Awardamount2`) ) as award2), concat(award2, '/', (`Awardcode3`, ':', `Awardamount3`) )) as award from table Y

but I got error.
Please tell me if my query is wrong or there is another to do this.
Thanks!
Lan

Options: ReplyQuote


Subject
Written By
Posted
if() query help needed
February 12, 2009 10:43AM
February 12, 2009 10:54AM
February 12, 2009 03:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.