Does anyone know how to use transact sql to enumerate the column types within a transact sql result set. I want to do something like this (pseudo-code):
for each column in (select * from table1 where id=uniquekey)
{
if (column.type=uniqueidentifier){
insert into #table2(id) values (column.value)
}}
then do some stuff with #table2
But I need to do it from within transact sql, and I don’t know in advance what the structure of table1 will be.
Anyone know how? I’m using MS SQL 2005. In a nutshell I want all uniqueidentifier values for a specific record in table1 to be written to #table2.
Thanks!
Warning, not tested: