I want to concatenate columns with a SELECT *
. For example:
SELECT * FROM Table1
Result:
Col1 Col2
---- ----
Joe Smith
I want to do something like SELECT CONCAT(*) FROM Table1
The reason I can't mention the columns by name is that they are being produced by a PIVOT from rows, so there could be any number these columns.
If anyone knows the answer, or knows how to Get the data from any number of rows into a single cell, separated by a comma, please let me know.
Best Answer
The
CONCAT
function requires passing column names explicitly and there is no such thing asCONCAT(*)
.On the other hand,
PIVOT
requires an explicit definition of the columns you are pivoting: if you are doing it dynamically, you probably have a variable that holds the names of the columns you are pivoting on and you could use the same variable in dynamic SQL with theCONCAT
function.