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. App轮播图

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. python生成html文件浏览器中文显示乱码问题

    近来在网上采集数据,想把采集下来的数据整合成html的形式保存.以便其他的平台产品可以直接读取html显示或者根据html标签提取数据. def output_html(self): try: fou ...

  3. HTML&CSS基础学习笔记1.10—添加链接

    我们可以设置链接的目标,使我们点击后可以跳转到我们想要去的地方. <a>标签的 href 属性用于指定超链接目标的 URL. 在页面中添加的<a>标签,浏览器会用特殊效果显示, ...

  4. iOS学习之页面之间传值的方式总结

    传值三种场景: 1.属性传值(从前往后传) 需求:第二个界面标签显示第一个界面输入框文字. 第一步, 在前一个界面定义属性. (语义属性声明为copy); 第二步, 在进入下一个界面之前,给属性传入数 ...

  5. IIC 概述之24c系列存储器内存分析

    IIC 型号     容量      器件/业面寻址字节                   可寻址位       模块 24C01   128B      (1010)(A2)(A1)(A0)(0或 ...

  6. 整型(int)转时间格式字符串及页面long型转时间格式字符串

    1,如果是封装的整型的话需要在后台进行处理再返回页面 处理过程是这样的 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm ...

  7. 提交svn报错说 有 unversioned 的文件

    这个说明   有未add的图片等东西,需要先add进去再提交

  8. Effective Java Item4:Enforce noninstantiability with a private constructor

    Item4:Enforce noninstantiability with a private constructor 通过构造私有化,禁止对象被实例化. public class UtilClass ...

  9. 数据结构&&算法基础知识

    写本篇主要是为了将基础知识梳理一遍,天天加一些基本东西,以后复习时可以返回来看看. 数据结构&&基础算法: 基本算法: 二分查找 二叉树: 二叉树的各种遍历 位操作: 排序: 排序算法 ...

  10. android 遍历所有文件夹和子目录搜索文件

    java代码: import java.io.File; import android.app.Activity; import android.os.Bundle; import android.v ...