sql循环查处多张表,表的结构相同,如何将查询出的表连接到一张表内:例如:
@beginMonth int(5),
@endMonth int(5)
as
while( @beginMonth<=@endMonth)
begin
select 。。。。。。。。。。。。。
end
sql循环查处多张表,如何连接到一张表内
答案:5 悬赏:80
解决时间 2021-12-12 04:59
- 提问者网友:风华是一指流沙
- 2021-12-11 21:59
最佳答案
- 二级知识专家网友:虚伪的现实
- 2021-12-11 22:27
declare @s varchar(2000)
...
set @s=''
while @beginmonth<=@endmonth
begin
select @s=@s+'select .... union all '
end
select @s=substring(@s,1,len(@s)-10)
execute @s
...
set @s=''
while @beginmonth<=@endmonth
begin
select @s=@s+'select .... union all '
end
select @s=substring(@s,1,len(@s)-10)
execute @s
全部回答
- 1楼网友:强势废物
- 2021-12-12 00:09
你的问题是两个问题 检查表结构,然后做修改,这是一步。 然后检索信息,是第二步。 至于你说的,对于符合规则的表,都执行,这个,恐怕有问题。 你的数据库既然设计的不合理,就修改下表结构即可,这很方便,完全没必要用程序去解决这个问题。 费时费力,另外,用vb的话,我恐怕是做不出来。
- 2楼网友:高冷不撩人
- 2021-12-11 23:57
多个表的名字如果.有没有什么相关连处?
如果没有..就只得去系统表中取表名了..复杂很多...
或者用union
如果有..那么就可以用while数据来做..
等下我来看回复..如果是我说的第二种情况..请提供表名..
- 3楼网友:佛说妍妍很渣
- 2021-12-11 23:50
select ... from ...
union all
select ... from ...
union all
select ... from ...
......
- 4楼网友:社会水太深
- 2021-12-11 23:26
while( @beginMonth<=@endMonth)
begin
select 。。。。。。。。。。。。。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |