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