sql 存储过程笔记
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 存储过程笔记的更多相关文章
- SQL存储过程笔记
一.概述 存储过程(Stored Procedure)是一组为了完成特定功能的SQL 语句集,经编译后存储在数据库.用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它. 优点: ...
- sql 存储过程笔记3
16:22 2014/1/26一.定义变量--简单赋值declare @a int set @a = 5 print @a --使用select语句赋值declare @user1 nvarchar( ...
- sql 存储过程笔记2
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sys_Page_v2]') and OBJECTPROPE ...
- 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试
<软件测试自动化之道>读书笔记 之 SQL 存储过程测试 2014-09-28 待测程序测试程序 创建测试用例以及测试结果存储 执行T-SQL脚本 使用BCP工具导入测试用例数据 ...
- ORACLE存储过程笔记3
ORACLE存储过程笔记3 流程控制 1.条件 if expression thenpl/sql or sqlend if; if expression thenpl/sql or sqlel ...
- ORACLE存储过程笔记1
ORACLE存储过程笔记1 一.基本语法(以及与informix的比较) create [or replace] procedure procedure_name (varible {IN|OUT ...
- PL/SQL存储过程编程
PL/SQL存储过程编程 /**author huangchaobiao *Email:huangchaobiao111@163.com */ PL/SQL存储过程编程(上) 1. Oracle应用编 ...
- SQL存储过程分页(通用的拼接SQL语句思路实现)
多表通用的SQL存储过程分页 案例一: USE [Community] GO /****** Object: StoredProcedure [dbo].[Common_PageList] Scrip ...
- SQL存储过程的调用及写法
调用函数: public class SqlProcess { ; public DataSet ReturnSet = null; public SqlDataAdapter adapter = n ...
随机推荐
- ajax的回调函数
ajax的回调函数(done,fail,always) 观看代码: $.ajax({ type: "post",//请求的类型 url: "/book/detail?ac ...
- idea设置包的导入和提示重复代码下波浪线
1.一般idea都不会导入包.即使按了(以下都是已eclipse设置idea的快捷键) alt+enter键也不能导入. 2.关闭重复代码提示(也就是重复代码有波浪线)
- [转]Java Jacob操作Excel
Jacob项目:https://sourceforge.net/projects/jacob-project/ 转自:https://blog.csdn.net/ZY_extreme/article/ ...
- Python3 循环_break和continue语句及循环中的else子句
break和continue语句及循环中的else子句break语句可以跳出for和while的循环体.如果你从for或while循环中终止,任何对应的循环else块将不执行. continue语句被 ...
- mysql安装报vcruntime140.dll缺失
mysql安装报:vcruntime140.dll缺失 安装:Visual C++ Redistributable for Visual Studio 2015 可以解决此问题
- layui checkbox , radio 清除所有选中项
方法: $(selector).prop('cjecked', false); form.render(); 使用示例: // 清除radio选中 $('input[name=ymd]').prop( ...
- Reactor系列(一)基本概念
基本概念 视频讲解:https://www.bilibili.com/video/av78731069/ 关注公众号,坚持每天3分钟视频学习
- Oracle 的查询-scott用户介绍
scott用户 密码tiger 解锁scott用户 alter user scott account unlock; 解锁scott密码(也可重置密码) alter user scott identi ...
- ubuntu 设置静态ip,但显示scope global secondary ens33
设置静态ip 修改 /etc/network/interfaces 文件 # The loopback network interface auto lo iface lo inet loopback ...
- JZOJ.1150【贪心算法】IQ
欢迎转载,请附上原链接https://www.cnblogs.com/Code-Garden/p/11276741.html(也没人会看) 一道对我来说较难的贪心题 题目描述 根据世界某权威学会的一项 ...