2

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.

1

1 Answer 1

5

The CONCAT function requires passing column names explicitly and there is no such thing as CONCAT(*).

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 the CONCAT function.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.