如何把查询出来的结果集插入到临时表?
已经查询出来的结果集是:
select 业务编号=t.yw_id,
项目编号 = t.xm_id,
当日收入金额 = isnull((select dr from t_bb2_in where xm_id = t.xm_id and rq ='2009-11-1' and dept_id='屋'),0.00) ,
累计收入金额 = isnull((select sum(dr) from t_bb2_in where xm_id = t.xm_id and (rq>='2009-11-1' and rq <= '2009-11-2') and dept_id='屋'),0.00),
日期 = '2009-11-2'
from t_bb2_xm t where t.status='启用' and yw_id='收入'
order by t.xm_id
-----------------------------------------------------------------------------------------------------------
我想上面的结果集插入到临时表#test1中,把这个结果集的字段作为#test1的字段,但是提示出错
错误信息为:服务器: 消息 1033,级别 15,状态 1,行 22
除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。
insert into #test1 select
(
select 业务编号=t.yw_id,
项目编号 = t.xm_id,
当日收入金额 = isnull((select dr from t_bb2_in where xm_id = t.xm_id and rq ='2009-11-1' and dept_id='屋'),0.00) ,
累计收入金额 = isnull((select sum(dr) from t_bb2_in where xm_id = t.xm_id and (rq>='2009-11-1' and rq <= '2009-11-2') and dept_id='屋'),0.00),
日期 = '2009-11-2'
from t_bb2_xm t where t.status='启用' and yw_id='收入'
order by t.xm_id
)
select 业务编号=t.yw_id,
项目编号 = t.xm_id,
当日收入金额 = isnull((select dr from t_bb2_in where xm_id = t.xm_id and rq ='2009-11-1' and dept_id='屋'),0.00) ,
累计收入金额 = isnull((select sum(dr) from t_bb2_in where xm_id = t.xm_id and (rq>='2009-11-1' and rq <= '2009-11-2') and dept_id='屋'),0.00),
日期 = '2009-11-2'
from t_bb2_xm t where t.status='启用' and yw_id='收入'
order by t.xm_id
-----------------------------------------------------------------------------------------------------------
我想上面的结果集插入到临时表#test1中,把这个结果集的字段作为#test1的字段,但是提示出错
错误信息为:服务器: 消息 1033,级别 15,状态 1,行 22
除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。
insert into #test1 select
(
select 业务编号=t.yw_id,
项目编号 = t.xm_id,
当日收入金额 = isnull((select dr from t_bb2_in where xm_id = t.xm_id and rq ='2009-11-1' and dept_id='屋'),0.00) ,
累计收入金额 = isnull((select sum(dr) from t_bb2_in where xm_id = t.xm_id and (rq>='2009-11-1' and rq <= '2009-11-2') and dept_id='屋'),0.00),
日期 = '2009-11-2'
from t_bb2_xm t where t.status='启用' and yw_id='收入'
order by t.xm_id
)
...全文
相关推荐
OCA认证分类模拟题7-附答案解析.doc
计算机考试认证模拟题-附答案解析
SQL 递归查询,并将结果集保存在临时表中
给定一个节点ID,查询此节点下的全部节点,并将结果集保存在临时表中
mysql临时表用法分析【查询结果可存在临时表中】
主要介绍了mysql临时表用法,结合实例形式分析了MySQL将查询结果存储在临时表中的相关操作技巧,需要的朋友可以参考下
oracle 临时表使用例子并用CURSOR返回结果集的例子
NULL 博文链接:https://zzwwxx603620070618180334.iteye.com/blog/825144
一个选查询后插入到一个临时表的oracle函数
一个选查询后插入到一个临时表的oracle函数


