如何把查询出来的结果集插入到临时表?

sdnwjd sdnwjd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
已经查询出来的结果集是:

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
)

...全文
评论 16
收藏 已收藏
分享
返回顶部
sdnwjd
MS-SQL Server 34,876 成员 254,635 内容