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. UnicodeEncodeError: 'ascii' codec can't encode characters

    将网页get到之后输入文本出现UnicodeEncodeError: 'ascii' codec can't encode characters错误 f = open('re.txt', 'w') u ...

  2. Spring Cloud(2):服务发现(Eureka)

    Spring Cloud Eureka是Spring Cloud Netflix项目下的一个模块,作用是服务的注册和发现,并实现服务治理.它有一个(或一组,以实现高可用)服务注册中心(eureka s ...

  3. JAVA 程序员代码生成利器

     http://www.grails.org/ 为什么要用Grails 采用groovy 开发,基于springboot+ hibernate ,groovy 语言层面运行效率稍微差点,但开发效率比j ...

  4. 利用canvas对图片进行切割

    使用input标签选择一张图片, 然后利用canvas对图片进行切割, 可以设置切割的行数和列数 这是html代码 ... <input type="file" id=&qu ...

  5. 【Web网站服务器开发】apache和tomcat 阿帕奇和汤姆猫

    经常在用apache和tomcat等这些服务器,可是总感觉还是不清楚他们之间有什么关系,在用tomcat的时候总出现apache,总感到迷惑,到底谁是主谁是次,因此特意在网上查询了一些这方面的资料,总 ...

  6. 【VS开发】程序员对内存的理解

    程序员对内存的理解 在C和C++语言开发中,指针.内存一直是学习的重点.因为C语言作为一种偏底层的中低级语言,提供了大量的内存直接操作的方法,这一方面使程序的灵活度最大化,同时也为bug埋下很多隐患. ...

  7. es5实现map/filter

    // ES5循环循环实现filter const selfFilter = function (fn, context) { let arr = Array.prototype.slice.call( ...

  8. linux的route

    参考: https://blog.csdn.net/u011857683/article/details/83795435 老男孩: https://blog.51cto.com/oldboy/974 ...

  9. 关于tk.mybatis.spring.mapper.SpringBootBindUtil$SpringBoot2Bind.bind(SpringBootBindUtil.java:129) ~[mapper-spring-boot-autoconfigure-1.2.3.jar:na]的问题

    错误如下: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at tk.mybatis.spring.m ...

  10. 在ASP.NET Core 2.0中使用Facebook进行身份验证

    已经很久没有更新自己的技术博客了,自从上个月末来到天津之后把家安顿好,这个月月初开始找工作,由于以前是做.NET开发的,所以找的还是.NET工作,但是天津这边大多还是针对to B(企业)进行定制开发的 ...