--本人的意思是想按照Test001表里面的fname字段里面的存储的内容来动态的建立多张表
--为什么最后只生成了一张表test3呢?
create table test001
(
fname varchar(10)
)insert into test001
select 'test1' union all
select 'test2' union all
select 'test3'
declare @sql as varchar(200),@fn as varchar(10)select @fn=fname
from test001set @sql='create table '+@fn+' (fname varchar(10))'exec (@sql)
from test001这里@fn的结果就只有test3,多个结果不能存在一个变量里
@sql=isnull(@sql,'')+'create table ['+fname+'](fname varchar(10)); '
from test001--print @sqlexec (@sql)
declare @sql nvarchar(1000)begin
select @sql=(select 'create table ['+fname+'](fname varchar(10)); ' as [text()] from test001 for xml path(''));
--print @sql
exec(@sql);
end