sql SP创建新批次

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SP创建新批次相关的知识,希望对你有一定的参考价值。

alter proc mk_NewBatch(
     @description varchar(60), 
     @cashaccount varchar(10), 
     @nextbatch varchar(15) output
) as

begin

     declare @thisbatch varchar(10)
     declare @lastbatchnum int
     declare @nextbatchnum int

     set nocount on

     select   top 1 @thisbatch = BATCH_NUM
     from      Batch 
     where     left(BATCH_NUM,6) = format(getDate(), 'yyMMdd')
     order by DATE_CREATED desc

     if (@thisbatch is null)
          begin
              set @nextbatchnum = 1
          end
     else
          begin
              select @lastbatchnum = convert(int,right(@thisbatch, len(@thisbatch)-patindex('%-%',@thisbatch)))
              set @nextbatchnum = @lastbatchnum + 1
          end

     set @nextbatch = format(getDate(),'yyMMdd') + '-' + convert(varchar(2), @nextbatchnum)

     insert into Batch (BATCH_NUM,ORG_CODE,STATUS,DESCRIPTION,DATE_CREATED,CREATED_BY,LAST_UPDATED,UPDATED_BY,CONTROLLED,CONTROL_COUNT,CONTROL_CASH,TRANS_COUNT,TRANS_CASH,CASH_PSUEDO,CASH_GL_ACCT,AR_PSUEDO,AR_GL_ACCT,EFFECTIVE_DATE,CASH_ENTITY,CASH_ACCOUNT_CODE,INTENT_TO_EDIT,SOURCE_SYSTEM,DUES_CYCLE_FLAG,MEETING,HAS_EXPORTED_TRANS,WEB_BATCH)
     values (
          @nextbatch,
          '',
          0,
          @description,
          getDate(),
          'MANAGER',
          getDate(),
          'MANAGER',
          0,
          0,
          0,
          0,
          0,
          '',
          (select GL_ACCOUNT from Cash_Accounts where CASH_ACCOUNT_CODE = @cashaccount),
          '',
          '',
          convert(varchar(10),getDate(),126),
          '',
          @cashaccount,
          '',
          '',
          0,
          '',
          0,
          0
     )
     
end

以上是关于sql SP创建新批次的主要内容,如果未能解决你的问题,请参考以下文章

我建立的sql列表出现'CREATE VIEW' 必须是查询批次中的第一个语句。

BAPI_BATCH_CREATE创建批次MCH1没有CUOBJ_BM值

使用sql语句怎么更改用户密码。或新建一个sysadmin权限的新用户

SQL在磁盘上创建了一个备份设备

装了一个新系统,安装SQL Server2008时, 先安装.net framework 3.5 sp1,可是安装时出错了,求解决!!

SQL server - 在创建之前检查 SP 中的对象是不是存在