I see what you are saying. I think you will need to do this in the query with some case statements. Checkout this site for help with that http://www.artfulsoftware.com/infotree/queries.php?&bw=1280 Or you could do a variable with an if statement where you use the value ($F{hour1}?$F{hour1} :$F{hour2}?"$F{hour2} etc :"") But , really what you want to do is change the db to use relational db. the code below is what I would do. and then your query would be like this which would give you what you want. select h.hour,c.name from data_table join hour_table as h on h.ref = c.hour_ref Code: Post Edited by Chris Collins at 01/27/09 17:56