SqlServer存储过程
新上线的车管系统,今天要给User添加权限,才发现这个后台加权限简直how to play ..
比如有人申请合肥的关务权限:
1.SITE 是合肥
2.ORG 有B81,P81,S81,M81等
3.关务权限包括5个functionId
所以,总共要有20条记录
问题是,后台操作界面 简直掉渣天,加一条权限,操作起码要有2~3分钟!!
只好想办法自己解决:
创建了一张配置表
写了一个存储过程
USE [In_Out_Control]
GO /****** Object: StoredProcedure [dbo].[sp_AddAuthority] Script Date: 11/04/2013 20:09:11 ******/
SET ANSI_NULLS ON
GO SET QUOTED_IDENTIFIER ON
GO -- =============================================
-- Author: donghao.li
-- Create date: 2013-11-04
-- Description: Authority
-- =============================================
CREATE PROCEDURE [dbo].[sp_AddAuthority]
-- Add the parameters for the stored procedure here
@empNo varchar(10),
@site varchar(10),
@authorityName varchar(50)
AS
BEGIN
SET NOCOUNT ON;
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
declare @org varchar(20),@functionId varchar(50),@empName varchar(30)
select @empName=emp_name from emp_data_all where emp_no=@empNo
if (@empName !='')
BEGIN
declare my_cursor cursor for
select org,functionId from C_IOC_USER_ABILITYCONTROL_TEMP where site=@site and authorityName=@authorityName order by org
open my_cursor
fetch my_cursor into @org,@functionId
while (@@fetch_status=0)
BEGIN
declare @isExist int
select @isExist=count(*) from c_ioc_usersite where org=@org and function_id=@functionId and emp_no=@empNo
-- Insert statements for procedure here
if (@isExist<=0)
BEGIN
insert into c_ioc_usersite(belong_company,emp_no,emp_name,company,site,org,active,function_id,create_date,create_by) values('BriView',@empNo,@empName,'briview',@site,@org,'Y',@functionId,getdate(),'C1226724')
END
fetch next from my_cursor into @org,@functionId
END
close my_cursor
deallocate my_cursor
END
end
GO
然后执行存储过程
USE [In_Out_Control]
GO DECLARE @return_value int EXEC @return_value = [dbo].[sp_AddAuthority]
@empNo = N'C1226724',
@site = N'BVHF',
@authorityName = N'库房' SELECT 'Return Value' = @return_value GO
好吧,这样方便快速了很多~
SqlServer存储过程的更多相关文章
- 解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)
解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译) http://improve.dk/where-does-sql-server-store-the-sourc ...
- Sqlserver 存储过程中结合事务的代码
Sqlserver 存储过程中结合事务的代码 --方式一 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ ...
- SqlServer存储过程学习笔记(增删改查)
* IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值. CREATE PROCEDURE [dbo].[PR_NewsAffiche_AddNewsEntity] ( ...
- SQLServer 存储过程嵌套事务处理
原文:SQLServer 存储过程嵌套事务处理 某个存储过程可能被单独调用,也可能由其他存储过程嵌套调用,则可能会发生嵌套事务的情形. 下面是一种解决存储过程嵌套调用的通用代码,在不能确定存储过程是否 ...
- 创建并在项目中调用SQLSERVER存储过程的简单示例
使用SQLSERVER存储过程可以很大的提高程序运行速度,简化编程维护难度,现已得到广泛应用.创建存储过程 和数据表一样,在使用之前需要创建存储过程,它的简明语法是: 引用: Create PROC ...
- SQLSERVER存储过程语法详解
CREATE PROC [ EDURE ] procedure_name [ ; number ] [ { @parameter data_type } [ VARYING ] [ = default ...
- SqlServer存储过程详解
SqlServer存储过程详解 1.创建存储过程的基本语法模板: if (exists (select * from sys.objects where name = 'pro_name')) dro ...
- sqlServer存储过程与sql语句的区别
sqlServer 存储过程与sql语句的区别 sql存储过程与sql语句的区别: 从以下几个方面考虑: 1.编写: 存储过程:编写比较难: sql语句:相对简单: 2.性能: 存储过程:高,可移 ...
- SqlServer存储过程(增删改查)
* IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值. CREATE PROCEDURE [dbo].[PR_NewsAffiche_AddNewsEntity] ( ...
- SQLSERVER存储过程的基本语法实例
SQLSERVER存储过程的基本语法实例 SQLSERVER存储过程的基本语法实例 一.定义变量--简单赋值 declare @a intset @a=5 print @a --使用select语句赋 ...
随机推荐
- oracle中统计重复几次的数据有几条
源地址:http://zhidao.baidu.com/link?url=ZgCztNzCScRI5kAqGqug1LJvf7IX311EQs6fJ0-W1kOtWaaR7MrtLoV_228Ed8F ...
- 89、Android EditText 悬浮停靠
package com.willen.topFloatDemo; import android.content.Context; import android.os.Handler; import a ...
- java小程序 示例 菲薄垃圾数列
package com.test; import java.util.Scanner; import org.junit.Test; import com.sun.xml.internal.ws.ap ...
- (easy)LeetCode 205.Isomorphic Strings (*)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- (easy)LeetCode 204.Count Primes
Description: Count the number of prime numbers less than a non-negative number, n. Credits:Special t ...
- 《Code Complete》ch.20 软件质量概述
WHAT & WHY ? 软件质量的特性 外在特性 正确性(Correctness) 可用性(Usability) 效率(Efficiency) 可靠性(Reliability) 完整性(In ...
- Cocos2d-x 3.0 事件系统【转】
事件系统,是一个软件的核心组成部分.从小处讲它是应用程序内部各模块交互的设计模式,从大处讲,它是软件架构的组成模块.在现代软件开发中,操作系统通常通过一些预定义的事件,告知应用程序发生的一些事情如用户 ...
- [转]SVN-版本控制软件
一.版本控制软件 1.为什么需要版本控制软件 问题:① 团队开发 ② 异地协作 ③ 版本回退 2.解决之道 SCM(Software Configuration Management):软件配置管理 ...
- Appnium移动自动化框架初探
作者:cryanimal QQ:164166060 本文简要介绍了appnium自动化框架的架构.加载流程.支持语言.相关配置,以及元素定位工具等. 官方网站: http://appium.io Ap ...
- DDDD
if (list != null && list.Count > 0) { result = ...