sql unite fields to one result

Posted by none on Stack Overflow See other posts from Stack Overflow or by none
Published on 2010-12-27T15:38:01Z Indexed on 2010/12/27 15:54 UTC
Read the original article Hit count: 154

Filed under:
|

i know this is a "not build in" or "the way dba thinks" but a programmer aproach , How could one request from 3 fields to get the one that is not null, into a result filed.

lets say we have a table with f1,f2,f3,f4,f5. lets say f2,f3,f4 are the same type.

lets say the content of the table be tupples of

(key1,null,null,value1,value2)
(key2,null,value3,value4,value5)
(key3,null,null,null,value6)

now if we return the first tupple then we get (key1) we get (key1,value1,value2) if we ask for key2 we get (key1,value3,value5) if we ask for key3 we get (key1,null,value6)

how is it possible to get the fields in the priority of if you have value in f2, then its set into the returned field, only then if we have value in f3 then its set into the middle returned field, only then if we have value in f4 then its set into the middle returned field

the main goal is to get the result into a sigel feild and prevent the overhead work needed at the result end.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about query