declare @channelid varchar(100)
set @channelid='''WH00026'',''WH00083'''
declare @sql varchar(1000)
if(object_id('tempdb.dbo.#ac') is not null)
begin
drop table #ac
end
create table #ac
(
channelid varchar(50),
pmoney decimal(18,2),
ptype tinyint,
inday varchar(10),
scale varchar(10),
comScale varchar(10)
)
set @sql='insert into #ac'
set @sql=@sql+' select a.channelid,a.pmoney,a.ptype,a.inday,a.scale,a.comScale'
set @sql=@sql+' from('
set @sql=@sql+' select oc.channelid,sum(totalFee) as pmoney,inday,scale,comScale,1 as ptype from orderCPS oc'
set @sql=@sql+' left join userInfo u on oc.channelid=u.channelid'
set @sql=@sql+' where inday between ''2016-10-13'' and ''2016-10-13'' and oc.channelid in ('+@channelid+') and (comOrderStatus is null or comOrderStatus=0)'
set @sql=@sql+' group by oc.channelid,inday,scale,comScale'
set @sql=@sql+' union all'
set @sql=@sql+' select oc.channelid,sum(totalFee) as pmoney,inday,scale,comScale,2 as ptype from orderCPS oc'
set @sql=@sql+' left join userInfo u on oc.channelid=u.channelid'
set @sql=@sql+' where inday between ''2016-10-13'' and ''2016-10-13'' and oc.channelid in ('+@channelid+') and orderStatus=0'
set @sql=@sql+' group by oc.channelid,inday,scale,comScale) a'
print @sql
exec(@sql);
select * from #ac
  

  

sql 创建临时表的更多相关文章

  1. sql创建临时表并且插入数据

    if OBJECT_ID('tempdb..#temp') is not null drop table #temp select * into #temp from ( --select * fro ...

  2. Sql Insert into select 创建临时表插入自增列

    ] GO ============================================= -- Author: PPL -- Create date: 2015-11-23 -- Desc ...

  3. sql server创建临时表的两种写法和删除临时表

    --创建.删除临时表 --第一种方式 create table #tmp(name varchar(255),id int) --第二种方式 select count(id) as storyNum ...

  4. SQL数据库中临时表、临时变量和WITH AS关键词创建“临时表”的区别

    原文链接:https://www.cnblogs.com/zhaowei303/articles/4204805.html SQL数据库中数据处理时,有时候需要建立临时表,将查询后的结果集放到临时表中 ...

  5. 如何实现SQL Server临时表的创建?

    以下的文章主要是对SQL Server临时表的创建的实际操作步骤,以及在实际操作中我们要用到的实际应用代码的介绍,我在一个信誉度很好的网站找到一个关于其相关内容今天拿出来供大家分享. 创建临时表 方法 ...

  6. SQL Server通过创建临时表遍历更新数据

    前言: 前段时间新项目上线为了赶进度很多模块的功能都没有经过详细的测试导致了生成环境中的数据和实际数据对不上,因此需要自己手写一个数据库脚本来更新下之前的数据.(线上数据库用是SQL Server20 ...

  7. sql中临时表的创建和使用【本文转自多人博客】

    本模块原网址:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/05/1526466.html 原作者:Jeff Wong 1.创建方 ...

  8. 一条sql语句引发mysql不停创建临时表的问题解决..coping to tmp table on desk

    (不懂临时表的先看 MySQL临时表 ) 首先,临时表只在当前连接可见,当关闭连接时,Mysql会自动删除表并释放所有空间.因此在不同的连接中可以创建同名的临时表,并且操作属于本连接的临时表.     ...

  9. sql Server 创建临时表 嵌套循环 添加数据

    begin --通过销货单与明细,生成安装项目及明细,及判断明细是否拆分生成多条 --delete from sazxm --delete from ssbazrw --获取未生成项目的销货单号 ,) ...

随机推荐

  1. Popular Cows (POJ No.2186)

    Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...

  2. var foo= {} ;foo.method() 和 单例模式有什么区别

    var Foo={} Foo.method = function() { var i = 0; return { a:function(){ console.log('aa', i++); }, b: ...

  3. px em rem

    px 在Web页面初期制作中,我们都是使用“px”来设置我们的文本,因为他比较稳定和精确.但是这种方法存在一个问题,当用户在浏览器中浏览我们制作的Web页面时,他改变了浏览器的字体大小,这时会使用我们 ...

  4. JVM调优总结 + jstat 分析(转)

    [转] JVM调优总结 + jstat 分析 JVM调优总结 + jstat 分析 jstat -gccause pid 1 每格1毫秒输出结果jstat -gccause pid 2000 每格2秒 ...

  5. [Python 3.x 官方文档翻译]Whetting Your Appetite 欢迎您的使用

    If you do much work on computers, eventually you find that there’s some task you’d like to automate. ...

  6. “声控”APP

    “声控”APP 编者:本文为携程机票研发部技术专家祁一鸣在携程技术微分享中的分享内容,关注携程技术中心微信公号ctriptech,获知更多一手干货. [携程技术微分享]是携程技术中心推出的线上公开分享 ...

  7. MySQL binlog_rows_query_log_events

    当binlog_format=statement的时候进制日志只记录的是SQL语句,当binlog_fromat=row的时候记录的是event,如果想要在row模式的情况下 也记录SQL语句:bin ...

  8. POJ 1755 Triathlon

    http://poj.org/problem?id=1755 题意:铁人三项,每个人有自己在每一段的速度,求有没有一种3条路线长度都不为0的设计使得某个人能严格获胜? 我们枚举每个人获胜,得到不等式组 ...

  9. HDU 3586 : Information Disturbing

    Problem Description In the battlefield , an effective way to defeat enemies is to break their commun ...

  10. Android 开机启动通知

    效果图: 学习: 1.静态注册实现开机启动 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLET ...