先问一句,这1000来张表是不是名字都是以group开头的,是的话这样
先得创建一张结果表,方便你将来查数据
1
select id,name,sex,age,addr into result from group1 where 1<>1
然后执行这个过程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
DECLARE c_cursor CURSOR FOR
Select name From sysobjects where name like 'group%' order by name
DECLARE @tablename varchar(100)
DELCARE @sql varchar(max) into @tablename
OPEN c_cursor
FETCH NEXT FROM c_cursor
WHILE <a href="
https://www.baidu.com/s?wd=%40%40FETCH_STATUS&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YvPH7bn1IWn1mdnv7hmhuh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHDLPj04rHRYnjTvP1f3P1mdrf" target="_blank" class="baidu-highlight">@@FETCH_STATUS</a> = 0
BEGIN
set @sql='insert into result select id,name,sex,age,addr from ' + @tablename + ' where name='<a href="
https://www.baidu.com/s?wd=%E7%8E%8B%E7%A3%8A&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YvPH7bn1IWn1mdnv7hmhuh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHDLPj04rHRYnjTvP1f3P1mdrf" target="_blank" class="baidu-highlight">王磊</a>''
exec (@sql)
FETCH NEXT FROM c_cursor into @tablename
END
CLOSE c_cursor
DEALLOCATE c_cursor