Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to cast a column to Varchar if the data type is XML in the below sql query?

SQL
select @ColumnList= @ColumnList+ ',' +
   column_name 
    from information_schema.columns  where
     table_name = @TableName  and DATA_TYPE not in ('timestamp')
Posted
Updated 15-Jul-15 3:50am
v2

1 solution

I take it you want to make the cast inside the string being built. If so, perhaps something like
SQL
select @ColumnList= @ColumnList+ ',' +
case 
   when data_type = 'xml' then 'cast(' + column_name + ' as varchar(max)'
   else column_name
end
from information_schema.columns  where
table_name = @TableName  and DATA_TYPE not in ('timestamp')
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900