--先建一个表 create table t(id int,name varchar(50)) --然后再copydeclare @n int set @n=1 while(@n<50) begin exec('select top 0 * into t'+cast(@n as varchar)+' from t' set @n=@n+1 end
打掉了符号,改下; --先建一个表 create table t(id int,name varchar(50)) --然后再copydeclare @n int set @n=1 while(@n<50) begin declare @sql varchar(50) set @sql='select top 0 * into t'+cast(@n as varchar)+' from t' exec(@sql) set @n=@n+1 end
怎么运行不了,我把表名t用 带空格表名代替declare @n int set @n=1 while(@n<50) begin exec('select top 0 * into t'+cast(@n as varchar)+' from 'table name'' set @n=@n+1 end
--先建一个表
create table t(id int,name varchar(50))
--然后再copydeclare @n int
set @n=1
while(@n<50)
begin
exec('select top 0 * into t'+cast(@n as varchar)+' from t'
set @n=@n+1
end
打掉了符号,改下;
--先建一个表
create table t(id int,name varchar(50))
--然后再copydeclare @n int
set @n=1
while(@n<50)
begin
declare @sql varchar(50)
set @sql='select top 0 * into t'+cast(@n as varchar)+' from t'
exec(@sql)
set @n=@n+1
end
set @n=1
while(@n<50)
begin
exec('select top 0 * into t'+cast(@n as varchar)+' from 'table name''
set @n=@n+1
end
select * into 新表
from tbName