declare @T table ( ID int primary key identity, Col1 varc...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @T table
(
  ID int primary key identity,
  Col1 varchar(20),
  Col2 varchar(20)
)

insert into @T values
('Row 1 Col 1', 'Row 1 Col2'),
('Row 2 Col 1', 'Row 2 Col2')


;with C(TableXML) as
(
  select *
  from @T
  for xml path('T'), type
)
select distinct T.X.value('local-name(.)', 'sysname') as ColumnName
from C
  cross apply C.TableXML.nodes('/T/*') as T(X)
where T.X.value('.', 'varchar(max)') like '%Col%'

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results