存储过程中使用临时表
2016-05-18 15:25
204 查看
CREATE PROCEDURE [dbo].[usp_UserFriendsOrder] @s varchar(MAX) as --如果临时表存在则先删除 if exists(select * from dbo.sysobjects where object_id('tempdb.dbo.#temp') is not null) delete from #temp else create table #temp(F_ID int,F_UserID char(36),F_FatherID int,F_Code varchar(18),F_UserName varchar(20),F_Phone varchar(11),F_CreateUser char(36),F_CreateDate datetime, F_State int,F_Uplevel varchar(8000),F_DownLevel varchar(8000),F_Level int) --执行存储过程usp_TUserRelationByFID 放入临时表 insert into #temp exec usp_TUserRelationByFID @s --查询临时表 -- select * from #temp BEGIN -- A.Currentcount 本月消费条数 -- B.Lastcount 上月消费条数 declare @sqlf_id varchar(MAX) set @sqlf_id='SELECT ltrim(Convert(numeric(9,2),case when B.Lastcount=0 then 0 else A.Currentcount*100.0/B.Lastcount end))+''%'' As Percentage, A.Currentcount,B.Lastcount FROM (SELECT count(*) as Currentcount FROM #temp INNER JOIN dbo.T_Order ON #temp.F_UserID = dbo.T_Order.F_CreateUser where dbo.T_Order.F_Remark!=''商家收银'' and datediff(month,dbo.T_Order.f_createdate,getdate())=0)as A,(SELECT count(*) as Lastcount FROM #temp INNER JOIN dbo.T_Order ON #temp.F_UserID = dbo.T_Order.F_CreateUser where dbo.T_Order.F_Remark!=''商家收银'' and datediff(month,dbo.T_Order.f_createdate,getdate())=1)as B' exec (@sqlf_id) end
相关文章推荐
- 机器学习中使用的神经网络第七讲笔记
- const成员变量与成员函数
- http://linux.linuxidc.com/
- Block的声明和线程安全
- Android仿美团分类下拉菜单实例代码
- @RequestMapping
- ruby system 的用法
- HDU5551
- 活动被收回后的恢复 --12
- EasyAR实现脱卡功能
- image大图缩小转成canvas后锯齿的问题
- 写个IOS应用程序,项目结构可以是这样......
- mysql命令大全
- 【Swift学习】Swift编程之旅---扩展(二十四)
- tp框架总体学习总结(一)
- .net CallBack::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩
- CLR Via C# 第一章(CLR的执行模型)——读书笔记
- Qt Creator 小例子 网上看到的
- virtualbox 网卡设置 主机 虚拟机互 ping 问题
- POJ 1597 find the nth digit (找规律)