如果在下面的sql查询中数据类型是XML,如何将列转换为Varchar?
问题描述:
如果在下面的sql查询中数据类型是XML,如何将列转换为Varchar?
How to cast a column to Varchar if the data type is XML in the below sql query?
select @ColumnList= @ColumnList+ ',' +
column_name
from information_schema.columns where
table_name = @TableName and DATA_TYPE not in ('timestamp')
答
我认为你想在正在构建的字符串中进行转换。如果是这样,也许类似
I take it you want to make the cast inside the string being built. If so, perhaps something like
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')