jeudi 6 mars 2014

SQL - Select only one value from multiple fields


Vote count:

0




Assume the following



col1 col2 col3 col4
------+----------+---------+---------
abc | | |


Yes, col1-4 have a space in them!


I want to select the column that is not a space . On row 1 it's col1, but on row 20 it may be col3, row 55 it may be col2, and so on. I need to return just that column.


There will always be only one column with a stored value within this range of four columns, I just need the one that actually has information in it.


This will be part of a greater query for a report, so regardless of what column abc is in I need that to look the same in every result case. Meaning I can't have the results be col1 for one case and col2 for the other because the report won't recognize. The column needs to always be called the same.


Yes, I know it's better to store NULLS versus spaces and why use four columns when only one can have data, why not use one. I've complained enougth about that so don't rip me a new one about bad db design because I AGREE.



asked 1 min ago

gSaenz

314





Aucun commentaire:

Enregistrer un commentaire