declare @sql varchar(2000), @tsql nvarchar(max), @split varchar(100)
set @sql='A,B,C,D,E' --保存的字符
set @split=','--分隔符
select @tsql='select ''' + replace(@sql,@split,''' AS New union all select ''') + ''' '
exec(@tsql)
create table T(id char(6), words varchar(100))
insert into T values('1', 'A,B,C,D,E')
--drop table T
declare @tsql varchar(100), @sentence varchar(100)
exec('select top 1 words from T where id=''1'' ')
--此处本尝试获得exec执行的结果(字符串),以用于下面的Replace函数第一个参数,但未找到方法;
select @tsql='select ''' + replace('A,B,C,D,E',',',''' AS New union all select ''') + ''' '
exec(@tsql)
浮云间
心有法竹
相关分类