declare @MyTable table ( ID int, A char(1), B char(1), C ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

declare @MyTable table
(
  ID int,
  A char(1),
  B char(1),
  C char(1),
  D char(1)
)  

insert into @MyTable values (6, '1', '2', '', null)

;with C(TableXML) as
(
  select *
  from @MyTable
  where ID = 6
  for xml path('T'), elements xsinil, 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)') <> ''

Enter Parameters

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