declare @T table ( Key1 int, Key2 varchar(10), ColumnKey ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

declare @T table
(
  Key1 int,
  Key2 varchar(10),
  ColumnKey varchar(10)
)
 
insert into @T values
(1,        'idx1',      'here'),
(2,        'idx2',      'there')


select stuff(T.X.query('Key1').value('.', 'varchar(max)'), 1, 1, '') as Key1,
       stuff(T.X.query('Key2').value('.', 'varchar(max)'), 1, 1, '') as Key2,
       stuff(T.X.query('ColumnKey').value('.', 'varchar(max)'), 1, 1, '') as ColumnKey
from 
  (
  select ','+cast(Key1 as varchar(10)) as Key1,
         ','+Key2 as Key2,
         ','+ColumnKey as ColumnKey
  from @T
  order by Key1
  for xml path(''), type
  ) T(X)

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached