create procedure SP_Wim_GetWorkSubSectionById(@paramId as int)
as
begin
declare @id as int;
declare @lvId as [nvarchar](20);
declare @mainID as [nvarchar](100);
declare @wsLv as int;
declare @wsState as int;
declare @resolveState as int;
declare @wsName as [nvarchar](100);
declare @wsTarget as [nvarchar](500);
declare @wsManager as [int];
declare @pBeginDt as [datetime];
declare @pEndDt as [datetime];
declare @pCycle as int;

create table #Temp(
[id] [int] IDENTITY(1,1) NOT NULL,
[wsId] [int] NULL,
[lvId] [nvarchar](20) NULL,
[mainID] [nvarchar](100) NULL,
[wsLv] [int] NULL,
[wsState] [int] NULL,
[resolveState] [int] NULL,
[wsName] [nvarchar](100) NULL,
[wsTarget] [nvarchar](500) NULL,
[wsManager] [int] NULL,
[pBeginDt] [datetime] NULL,
[pEndDt] [datetime] NULL,
[pCycle] [int] NULL
)

--select * from Wim_WorkSection where id=@paramId
insert into #Temp ([wsId],[lvId],[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],[pCycle]) select [id],'0',[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],IsNull([pCycle],0) from Wim_WorkSection where id=@paramId
declare @num as varchar(20);
declare @allws as varchar(500);
declare @tempid as int;
DECLARE items_cursor CURSOR LOCAL FORWARD_ONLY STATIC READ_ONLY
FOR
select dbo.[Fuc_GetwsNumber](id) as num,REPLACE(dbo.[Fuc_Getwsallws](id),'|',',') as allws,id from Wim_WorkSection where wsParentID=1106
OPEN items_cursor
FETCH NEXT from items_cursor INTO @num,@allws,@tempid
WHILE @@FETCH_STATUS = 0
BEGIN
insert into #Temp ([wsId],[lvId],[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],[pCycle]) select [id],@num,[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],IsNull([pCycle],0) from Wim_WorkSection where id=@tempid
if(@allws!='')
begin
SELECT @num=@num+'.0'
insert into #Temp ([wsId],[lvId],[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],[pCycle]) select [id],@num,[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],IsNull([pCycle],0) from Wim_WorkSection
where id IN (select id from Wim_WorkSection where wsParentID=@tempid)
end

FETCH NEXT FROM items_cursor INTO @num,@allws,@tempid
END
CLOSE items_cursor
DEALLOCATE items_cursor
--查询临时表的数据
select * from #Temp
end

exec SP_Wim_GetWorkSubSectionById 1106;

drop SP_GetWorkSubSectionById

SELECT * FROM Wim_WorkSection where wsParentID=1106

insert into #Temp ([wsId],[lvId],[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],[pCycle])

select [id],1,[mainID],[wsLv],[wsState],[resolveState],[wsName],[wsTarget],[wsManager],[pBeginDt],[pEndDt],IsNull([pCycle],0) from Wim_WorkSection
where id IN (select id from Wim_WorkSection where wsParentID=1111)

create proc proc_name
as
sql_text
DECLARE cur_name CURSOR
for
sql_text
OPEN items_cursor
FETCH NEXT from cur_name INTO @name....
WHILE @@FETCH_STATUS = 0
BEGIN
sql_text
END
CLOSE cur_name
DEALLOCATE cur_name

sql 存储过程笔记的更多相关文章

  1. SQL存储过程笔记

    一.概述 存储过程(Stored Procedure)是一组为了完成特定功能的SQL 语句集,经编译后存储在数据库.用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它. 优点:   ...

  2. sql 存储过程笔记3

    16:22 2014/1/26一.定义变量--简单赋值declare @a int set @a = 5 print @a --使用select语句赋值declare @user1 nvarchar( ...

  3. sql 存储过程笔记2

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sys_Page_v2]') and OBJECTPROPE ...

  4. 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试

    <软件测试自动化之道>读书笔记 之 SQL 存储过程测试 2014-09-28 待测程序测试程序   创建测试用例以及测试结果存储  执行T-SQL脚本  使用BCP工具导入测试用例数据  ...

  5. ORACLE存储过程笔记3

    ORACLE存储过程笔记3 流程控制 1.条件   if expression thenpl/sql or sqlend if;   if expression thenpl/sql or sqlel ...

  6. ORACLE存储过程笔记1

    ORACLE存储过程笔记1 一.基本语法(以及与informix的比较)   create [or replace] procedure procedure_name (varible {IN|OUT ...

  7. PL/SQL存储过程编程

    PL/SQL存储过程编程 /**author huangchaobiao *Email:huangchaobiao111@163.com */ PL/SQL存储过程编程(上) 1. Oracle应用编 ...

  8. SQL存储过程分页(通用的拼接SQL语句思路实现)

    多表通用的SQL存储过程分页 案例一: USE [Community] GO /****** Object: StoredProcedure [dbo].[Common_PageList] Scrip ...

  9. SQL存储过程的调用及写法

    调用函数: public class SqlProcess { ; public DataSet ReturnSet = null; public SqlDataAdapter adapter = n ...

随机推荐

  1. flutter Android打包

    以下内容均是在mac版本电脑上的操作 1.生成签名 //根目录执行以下命令 keytool -genkey -v -keystore ~/sign.jks -keyalg RSA -keysize 2 ...

  2. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-2.微信扫一扫功能开发前期准备

    笔记 2.微信扫一扫功能开发前期准备         简介:讲解微信扫一扫功能相关开发流程和资料准备              1.微信开放平台介绍(申请里面的网站应用需要企业资料)          ...

  3. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA

    笔记 2.快速搭建SpringBoot项目,采用IDEA     简介:使用SpringBoot start在线生成项目基本框架并导入到IDEA中 参考资料:         IDEA使用文档    ...

  4. 安装php的sphinx扩展模块

    转自 http://blog.csdn.net/fenglailea/article/details/38115821 首先你必须已经安装过了sphinx 如何安装sphinx请看:http://bl ...

  5. 记一次排查mysql数据库连接未关闭问题的过程

    在一些项目中由于一些特殊原因仍然保留着显示的获取数据库连接(Connection).提交事务.回滚事务.关闭连接等操作:其中关闭连接是比较容易疏忽又比较难在前期发现的问题. 我是如何排查连接未关闭的问 ...

  6. Kubernetes Dashboard的安装与坑【h】

    1.前言 https://github.com/kubernetes/dashboard/releases kubectl apply -f https://raw.githubusercontent ...

  7. lua学习笔记2--table

    table是lua中的一种"数据/代码结构",可以用俩创建不同的"数据类型"lua语言中的数组其实就是table类型 array = {, , , , } pr ...

  8. nginx 代理 registry docker certificate is valid for k8s, not

    1.配置SSL证书及nginx反向代理docker registry 搭建私有CA,初始化CA环境,在/etc/pki/CA/下建立证书索引数据库文件index.txt和序列号文件serial,并为证 ...

  9. linux网络route

    一.网络基础知识: 设备端获取的IP路由表 [root@HKVS /] # route –n Kernel IP routing table Destination     Gateway       ...

  10. Linux安装redis logstash

    一.安装redis tar -zxvf redis-3.2.8.tar.gz cd redis-3.2.8 make  && make install PREFIX=/usr/loca ...