SQL: can you select certain cols...???

From: <schapman_at_schapman.pdial.interpath.net>
Date: 1995/04/01
Message-ID: <3lih6p$siu_at_redstone.interpath.net>#1/1


Please help:

Is there a way to select 5 columns out of a table with 30 columns (of the same data type) based on the column values?

We have a instrument result table of a primary key, and 30 cols for element readings. Most are 0, but for different samples, different elements show up as some non-zero value. For example:

Cols: Elem1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... Values: 0 0 1.4 5.3 0 4.5 0 0 0 2.3 0 3.1 0 0 0 ...

I want to retrieve the values 1.4, 5.3, 4.5, 2.3, and 3.1 (including the column names so that I know where the values came from).

For reports (Crystal) and output screens, the user only wants to see the first 5 element columns that are <> 0. Is there a way to do this in a SQL?

I figured out how to get the first one:

SELECT DECODE(Elem1, 0, DECODE(Elem2, 0, ..., Elem2), Elem1) AS FirstGoodElem FROM My_Table
WHERE Primary_Key = PK

But for the second element, how do you bypass the first one already obtained?

Much thanks,
Steve Chapman
schapman_at_schapman.pdial.interpath.net 74073.3010_at_compuserve.com
---------------------This is my signature file!---------------------

xxxxxxxxx  xxxxxxxxx  xxxxxxxxx  x       x  xxxxxxxxx   xxxxxxx     
x              x      x          x       x  x          x       x    
x              x      xx         x       x  xx         x            
xxxxxxxxx      x      xxx         x     x   xxx        x            
        x      x      xx           x   x    xx         x            
        x      x      x             x x     x          x       x    
xxxxxxxxx      x      xxxxxxxxx      x      xxxxxxxxx   xxxxxxx    x

--------------------------------------------------------------------
Received on Sat Apr 01 1995 - 00:00:00 CEST

Original text of this message