I need my select to have a pattern like this:
SELECT '<text> ' + tbl.* + ' </text>' FROM table tbl;
The ideal solution would have all the columns separated by a comma in order to have that output:
SQL result for Table 1 with two columns:
'<text>col1, col2</text>'
SQL result for Table 2 with three columns:
'<text>col1, col2, col3</text>'
I tried to use the CONCAT(...) function like this:
SELECT CONCAT('<text>', tbl.*, '</text>')
FROM table2 tbl
But I understand it is not so simple because the variable number of columns.
Is there any simple solution to address that problem?
I am using SQL Server 2008 R2.
Any number of columns for a given tablename;
If you need column names wrapped with
<text>SQL Fiddle Example here
If you need select query result set wrapped with
<text>then;SQL Fiddle Example here