Logical OR on Columns? (Merging two or more columns into one column)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc Floessel

    Logical OR on Columns? (Merging two or more columns into one column)

    Considering the following example table:

    Column1 | Column2 | Column3
    =============== ============
    NULL |"Value1" | NULL
    ---------------------------
    "Value2"| NULL | NULL
    ---------------------------
    NULL | NULL |"Value3"

    In each row only one column contains an actual value (a string in our
    example), the other columns are set to NULL.

    I would like to merge those columns into one single column, discarding
    the NULL entries.

    The desired result would look like this:

    Merged_Column
    =============
    "Value1"
    -------------
    "Value2"
    -------------
    "Value3"

    A '"SELECT column1 OR column2 OR column3 as "Merged_Column" ' doesn't
    work unfortunately. Is there an easy way to accomplish this on the SQL
    Server?

    The next problem I am going to face is that every column is in fact
    made of a different data type (ie. Date, Int). Is there a way to
    modify the merge select (if that's possible) to have it cast
    everything into a single specific type? Ie. make everything in the
    merged column a string.

    Thanks,
    Marc Floessel
Working...