在存储过程里创建临时表,往表中直接插入数据

摘要:
--每页多少3@CurrPageint--当前页面45AS6begin7创建表#temp_表(8Row_Identity(1,--name 12ItemTypeint--类型1314)151617--计划18插入到#temp_表格(ItemGuid,
在存储过程里创建临时表,往表中直接插入数据第1张在存储过程里创建临时表,往表中直接插入数据第2张
 1 CREATE PROCEDURE [dbo].[Proc_PX_Practice]
 2 @PageSize int, --每页多少个
 3 @CurrPage int --当前页
 4 
 5 AS
 6 begin
 7      create table #temp_table(
 8                               Row_ID int identity(1,1) primary key not null,  --Row_ID 自增长
 9                               ItemGuid varchar(50),       --Guid
10                               PlanGuid varchar(50), 
11                               Name varchar(50),          --名称
12                               ItemType int               --类型
13 
14                               )                              
15                     
16 
17     --计划
18     insert into #temp_table(ItemGuid,PlanGuid,Name,ItemType) 
19     (
20     select RowGuid,RowGuid,PlanName,'0' from PX_plan
21     )
22 
23     --课程
24     insert into #temp_table(ItemGuid,PlanGuid,Name,ItemType) 
25     (
26     select CourseGuid,PlanGuid,CourseName,'1' from PX_PlanCourse where 
27      PlanGuid in (select PlanGuid from #temp_table where ItemType='0')
28      
29     ) 
30 
31     --课件
32     insert into #temp_table(ItemGuid,PlanGuid,Name,ItemType) 
33     (
34     select a.RowGuid,b.PlanGuid,a.Name,'2' from PX_CourseWare a, #temp_table b where 
35       a.CourseGuid=b.ItemGuid and b.ItemType='1'
36     )
37 
38 
39     --output
40    declare @StrSql varchar(max)
41    declare @TopIndex int
42    set @TopIndex = (@CurrPage-1)*@Pagesize
43    set @StrSql='select top '+str(@Pagesize)+' * from #temp_table where  ItemGuid not in (select top '+str(@TopIndex)+' ItemGuid from #temp_table order by Row_ID) order by Row_ID '
44    
45    exec (@StrSql)
46 
47 
48        select * from #temp_table order by ItemType 
49      
50  end
51 
52 
53 
54 
55 
56 
57 
58 GO
View Code

免责声明:文章转载自《在存储过程里创建临时表,往表中直接插入数据》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇php关于mysql长连接问题nginx配置ssl证书实现https访问下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

sysbench对自装MySQL数据库进行基准测试

一、 安装sysbench wget https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh chmod +x script.rpm.sh ./script.rpm.sh yum install -y sysbench 二、准备测试表 sysbench //...

MySQL三种备份

一)备份分类 1 2 3 4 5 6 7 8 9 10 11 12 冷备:cold backup数据必须下线后备份 温备:warm backup全局施加共享锁,只能读,不能写 热备:hot backup数据不离线,读写都能正常进行 备份的数据集 完全备份:full backup 部分备份:partial backup 备份时的接口(是直接备份数据文...

华为网络设备常用命令

华为交换机配置端口表示方法E1/0/1显示系统版本信息:display version显示诊断信息:display diagnostic-information显示系统当前配置:display current-configuration显示系统保存配置: display saved-configuration显示接口信息:display interface...

Nginx日志运维笔记

在分析服务器运行情况和业务数据时,nginx日志是非常可靠的数据来源,而掌握常用的nginx日志分析命令的应用技巧则有着事半功倍的作用,可以快速进行定位和统计。 1)Nginx日志的标准格式(可参考:http://www.cnblogs.com/kevingrace/p/5893499.html) log_format main '$remote_ad...

mysql 基本使用教程(源于网络)

3.1. 连接与断开服务器 3.2. 输入查询 3.3. 创建并使用数据库 3.3.1. 创建并选择数据库 3.3.2. 创建表 3.3.3. 将数据装入表中 3.3.4. 从表检索信息 3.4. 获得数据库和表的信息 3.5. 在批处理模式下使用mysql 3.6. 常用查询的例子 3.6.1. 列的最大值 3.6.2. 拥有某个列的最大值的行...

oracle中如何创建表的自增ID(通过序列)

1、什么是序列呢?     序列是一数据库对象,利用它可生成唯一的整数。一般使用序列自动地生成主码值。一个序列的值是由特别的Oracle程序自动生成,因而序列避免了在运用层实现序列而引起的性能瓶颈。 Oracle序列允许同时生成多个序列号,而每一个序列号是唯一的。 当一个序列号生成时,序列是递增,独立于事务的提交或回滚。容许设计缺省序列,不需指定任何子句。...