sql的存储过程调用

USE [ChangHong_612]
GO
/****** Object: StoredProcedure [dbo].[st_MES_GetCodeRule] Script Date: 09/10/2015 17:44:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[st_MES_GetCodeRule] (
@in_CodeRuleName varchar(50) = ‘‘ --规则名称
, @in_BillNO varchar(50) = ‘‘ --传入的单据编码
, @in_User varchar(20) = ‘‘
, @OutCode varchar(50) = ‘‘ output
, @ShowRs bit = 1
)
/*************
exec [st_MES_GetCodeRule] ‘MouldNO‘,‘‘
select * from Sys_CodeRuleChild
creator: Wuchun
create date: 2012.11.06
Remark: 按编码规则产生相应编码
**************/
as
begin
declare @code varchar(200), @DeptCode varchar(20), @SNO varchar(20)
declare @RuleID int, @CodeRuleNo varchar(50), @InitValue varchar(50), @length int , @Level int
select @RuleID = RuleID from Sys_CodeRule where CodeRuleEName = @in_CodeRuleName and state = 1
select @Code = ‘‘, @DeptCode = ‘‘, @SNO = ‘‘
declare cur cursor for
select CodeRuleNo, InitValue, length, level
from Sys_CodeRuleChild
where RuleID = @RuleID
order by level
open cur
fetch next from cur into @CodeRuleNo, @InitValue, @length, @Level
while(@@fetch_Status = 0)
begin
if(@CodeRuleNO = ‘Date‘)
select @Code = @Code+convert(varchar(8),getdate(),112)
else if(@CodeRuleNO = ‘BillNO‘)
select @Code = @Code+ rtrim(@in_BillNO)
else if(@CodeRuleNO = ‘SN‘) --流水号
begin
exec st_MES_GetCodeInitValue @SNO output, @RuleID, @Level, @CodeRuleNO, @Length, @InitValue
select @Code = @Code+ rtrim(@SNO)
end
else if(@CodeRuleNO = ‘Define‘)
select @Code = @Code + rtrim(@InitValue)
else if(@CodeRuleNO = ‘EmpID‘)
select @Code = @Code + rtrim(@in_user)
else if(@CodeRuleNO = ‘DeptCode‘)
begin
select @DeptCode = DeptCode from sys_user where UserCode = @in_User
select @Code = @Code + @DeptCode
end
fetch next from cur into @CodeRuleNo, @InitValue, @length, @Level
end
close cur
deallocate cur

--Output
select @OutCode = @Code
if @ShowRs = 1
select Code = @Code
end

----------------------------------------------------------------

USE [ChangHong_612]
GO
/****** Object: StoredProcedure [dbo].[st_MES_GetCodeInitValue] Script Date: 09/10/2015 17:46:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[st_MES_GetCodeInitValue] (
@ret varchar(20) output
, @in_RuleID int
, @in_Level int
, @in_CodeRuleNO varchar(20) = ‘‘
, @in_Length int
, @in_InitValue varchar(20) = ‘‘
)
/*************
creator: Wuchun
create date: 2012.11.06
Remark: 按编码规则流水号值
**************/
as
begin
begin tran
if (not exists(select 1 from Sys_CodeRuleValue
where RuleId = @in_RuleID and level = @in_Level and CodeRuleNo = @in_CodeRuleNO))
begin
if @in_InitValue = ‘‘
select @in_InitValue = ‘1‘
else
begin
if isnumeric(@in_InitValue) = 1
select @in_InitValue = convert(int,@in_InitValue)+1
else
select @in_InitValue = ‘1‘
end

insert into Sys_CodeRuleValue(RuleID,CodeRuleNO, Level,value,updateTime)
select @in_RuleID, @in_CodeRuleNO, @in_Level, @in_InitValue, getdate()
end
else
begin
select @in_InitValue = value
from Sys_CodeRuleValue with(rowlock,xlock)
where RuleId = @in_RuleID and level = @in_Level
and CodeRuleNo = @in_CodeRuleNO
select @in_InitValue = convert(int,@in_InitValue)+1
update Sys_CodeRuleValue with (rowlock) set value = @in_InitValue, updateTime = getdate()
where RuleId = @in_RuleID and level = @in_Level
and CodeRuleNo = @in_CodeRuleNO
end
commit tran
select @ret = replace(str(right(@in_InitValue,@in_Length), @in_Length), space(1), ‘0‘)

end

时间: 2024-10-13 01:24:54

sql的存储过程调用的相关文章

sql server存储过程调用C#编写的DLL文件

新建C#类库,编译. 添加引用 using Microsoft.SqlServer.Server; 方法 [SqlFunction] public static int GenerateTxt() { ...... } 修改数据库配置 ---修改配置 exec sp_configure 'clr enabled', 1; reconfigure; 根据dll路径注册程序集 --从dll中抽取中间语言(IL) USE erp303_szzb_szpa CREATE ASSEMBLY Custome

toad调用存储过程,存储过程调用sql 类

1.定义一个sql 类Hello DROP JAVA SOURCE NEWXZXT."Hello"; CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED NEWXZXT."Hello" as import java.lang.*; public class Hello { public static String say(String args) { System.out.println(args); return arg

VS中调用SQL SERVER存储过程

 存储过程是经过编译的,永久保存在数据中的一组SQL语句,通过创建和使用存储过程可以提高程序的重用性和扩展性,为程序提供模块化的功能,还有利于对程序的维护和管理.下面就详谈一下,VB.NET如何调用SQL SERVER中的存储过程. 以上就是本人数据库中的一张表-OnDutyInfo 创建存储过程 <span style="font-size:18px;">create procedure pro_OnDutyInfo --存储过程名 @teacherID char(1

Cpp 调用sql server 存储过程时不返回output参数解决办法

Cpp 调用sql server 存储过程时不返回output参数,但是在ssms中调用的时候能正常返回,貌似数据库和应用代码是一切正常,再测试用c#调用也能正常获取output参数,在存储过程的的开始加上set nocount on,就能解决这个问题. 墙外原文件:点击打开链接

oracle 存储过程 调用动态sql

oracle 存储过程 调用动态sql CreationTime--2018年8月16日11点25分 Author:Marydon 1.错误实现方式 --开始时间拼接' 00:00:00' V_SQL := 'select decode(length(' || V_END || '),10,' || 'concat(' || V_END || ', 00:00:00),' || V_END || ') from dual'; EXECUTE IMMEDIATE V_SQL; 编译成功,但是存储过

sql server 查询某个表被哪些存储过程调用

原文:sql server 查询某个表被哪些存储过程调用 sql server 查询某个表被哪些存储过程调用 select distinct object_name(id) from syscomments where id in (select id from sysobjects where type ='P') and text like'%TableName%' 原文地址:https://www.cnblogs.com/lonelyxmas/p/9491635.html

Sql分页存储过程及调用

Alter Proc P_Page( @TblName varchar(200), --表名 @PageSize int, --每页显示条数 @PageIndex int = 1, --页面索引(页码) @strGetFields varchar(1000)='*', --无传入值,则搜索所有列 @OrderType int = 0, --是否倒序(0=否,1=是) @FldName varchar(100), --以什么条件进行倒叙 @StrWhere varchar(2000), --查询条

Hibernate4调用SQL和存储过程

最近使用了新的Struts2.20+spring4.0+hibernate4.0,新框架移除了HibernateSupportDao,所以重写了下Hibernate4对SQL和存储过程的操作,以备后查 以下的sessionFactory 对象是通过spring注入 1 private SessionFactory sessionFactory; 2 public void setSessionFactory(SessionFactory sessionFactory) { 3 this.sess

SQL Server存储过程的初步认知

什么是存储过程? 存储过程就是作为可执行对象存放在数据库中的一个或多个SQL命令.实际上存储过程就是能完成一定操作的一组SQL语句. 为什么要用存储过程? 1.  存储过程只在创造时候编译,以后每次执行存储过程都不需要再重新的编译,而一般的SQL语句每执行一次就需要编译一次,所以使用存储过程可提高数据库执行速度. 2.  当对数据库进行复杂操作时,可将此复杂操作用存储过程封装起来与数据库提供的事物处理结合在一起. 3.  存储过程可以重复的使用,降低开发人员的工作量,提高工作效率. 4.  安全