Read Using SQL Snippets before using any of this site's code or techniques on your own systems.

Columns to String

This section presents techniques for taking values from multiple columns, like these,

VAL_1  VAL_2  VAL_3  NOTE
------ ------ ------ -------------------------
a                    One NOT NULL, Two NULL
       b             One NOT NULL, Two NULL
              c      One NOT NULL, Two NULL
a      b             Two NOT NULL, One NULL
a      b      c      Three NOT NULL, Zero NULL
                     Zero NOT NULL, Three NULL
 

and assembling them into a single, delimited string like this

STRING
--------------------
a
b
c
a,b
a,b,c
 

or this

STRING
--------------------
a,,
,b,
,,c
a,b,
a,b,c
,,
 

or this.

XML_STRING
--------------------------------------------------
<VAL_1>a</VAL_1>
<VAL_2>b</VAL_2>
<VAL_3>c</VAL_3>
<VAL_1>a</VAL_1><VAL_2>b</VAL_2>
<VAL_1>a</VAL_1><VAL_2>b</VAL_2><VAL_3>c</VAL_3>