First, I think your data structure is wrong. Like data should be in a single column, like an attribute column. This provides scalability (no limit on attributes) and efficiency (no empty columns).

But, since you are probably stuck with what you have, try something like this:

SELECT CONCAT(KeyField,"|",Attrib1,"\n") AS Attrib1,
CONCAT(KeyField,"|",Attrib2,"\n") AS Attrib2,
CONCAT(KeyField,"|",Attrib3,"\n") AS Attrib3
FROM dbname ...

Depending on your platform you would change "\n" (new line) to "\r" (return) or both. This will give you a sudo new line. I just threw the pipe in as a separator, but that could be anything you want.

On Sep 10, 2004, at 10:11 AM, [EMAIL PROTECTED] wrote:

I have a table that has a structure similar to this

| KeyField  | Attrib1 | Attrib2 | Attrib 3 |

What I need to do for a report that I need to generate is break this into
multiple rows, as


| KeyField  | Attrib1 |
| KeyField  | Attrib2 |
| KeyField  | Attrib3 |

Key field is not unique, and obviously I'd prefer if the result table was
actually


| KeyField  | Attrib |

so that I can suppress rows where Attrib contains no data.

I can think of several ways to do this, but they're all too convoluted for
the system we're using here. Ideally, it should be in a single SELECT
statement. I've tried subqueries and temporary tables but I've been unable
to make this work.


Any pointers that anyone can give me?

--
Dave Weingart, Sr. Programmer/Analyst "I can call modules from the vasty
Private Label Services deep." -- "Why, so can I, or so
can
Voice: +1-516-682-1470 any programmer. But will they run
FAX : +1-516-496-3160 when you do call for them?"


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to