首页 新闻 会员 周边

存储过程中向临时表插入数据问题。

0
悬赏园豆:15 [已解决问题] 解决于 2016-10-14 17:35

详细如下:
Select Count(1) from A
Select Count(1) from B
如何能将A表与B表查询出来的这个结果在存储过程中分条插入临时表?
插入后例:

#temp 
Name Value
'A'     10
'B'     20

求大神指教,能做到么?

时光未曾老去.的主页 时光未曾老去. | 初学一级 | 园豆:7
提问于:2016-01-11 21:35
< >
分享
最佳答案
1

-- 若#temp不存在

select * into #temp from
(
    select 'A' as [Name], count(1)as [Value] from A
    union all
    select 'B' as [Name], count(1)as [Value] from B
)t

-- 若#temp已存在
insert into #temp
select 'A', count(1) from A
union all
select 'B', count(1) from B

收获园豆:15
脚本王子 | 小虾三级 |园豆:779 | 2016-01-12 16:29
其他回答(1)
1

用游标试试啊

jello chen | 园豆:7306 (大侠五级) | 2016-01-12 08:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册