declare @s varchar(8000)
declare tb cursor local for
select 'alter table ['+name+'] add 列名 int' --添加字段的sql语句
from sysobjects
where name like 'T200407%' --要添加字段的表名应该满足的条件
open tb
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
declare tb cursor local for
select 'alter table ['+name+'] add 列名 int' --添加字段的sql语句
from sysobjects
where name like 'T200407%' --要添加字段的表名应该满足的条件
open tb
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
set @i=1
while @i<=31
begin
set @tname='T200407'+right('00'+cast(@i as varchar),2)
exec('
if not exists (select * from sysobjects a,syscolumns b where a.id=b.id and a.name='''+@tname+''' and b.name=''colname'')
ALTER TABLE @tname ADD colname int NULL
')
end