zoukankan      html  css  js  c++  java
  • 生成单据编号的存储过程

    USE [crm2]
    GO
    /****** Object: StoredProcedure [dbo].[GetBillsID] Script Date: 09/22/2018 15:13:35 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- Batch submitted through debugger: SQLQuery1.sql|0|0|C:UsersadminAppDataLocalTemp~vsC414.sql
    ALTER PROCEDURE [dbo].[GetBillsID]
    (@Billsmode INT=0,
    @BillsType VARCHAR(30), 
    @DateType varchar(30),
    @GetId int
    )
    
    AS
    BEGIN
    -- routine body goes here, e.g.
    -- SELECT 'Navicat for SQL Server'
    if (@billsmode=0) 
    BEGIN
    if (exists(select ( BillsID.DateCount) from BillsID where BillsType=@billsType and DateType=@DateType)) 
    BEGIN
    select @GetId=BillsID.DateCount from BillsID where BillsType=@billsType and DateType=@DateType
    set @GetId=@getid+1
    select @BillsType+'-'+CONVERT(varchar(100),@DateType ,23)+'-'+replace(right(str(@GetId),4),' ','0')
    update dbo.BillsID with (TABLOCKX) set DateCount=@Getid where (BillsType=@billsType and DateType=@DateType)
    end 
    else
    begin
    set @GetId=@getid+1
    select @BillsType+'-'+CONVERT(varchar(100),@DateType ,23)+'-'+replace(right(str(@GetId),4),' ','0')
    INSERT INTO dbo.BillsID with (TABLOCKX) (BillsType,DateType,DateCount) VALUES (@BillsType,@DateType,@GetId)
    end    
    END 
    if (@billsmode=1) 
    BEGIN
    if (exists(select ( BillsID.MonthCount) from BillsID where BillsType=@billsType and MonthType=left(convert(varchar,@DateType,21),7)))
    BEGIN
    select @GetId=BillsID.MonthCount from BillsID where BillsType=@billsType and MonthType=left(convert(varchar,@DateType,21),7)
    set @GetId=@getid+1
    select @BillsType+'-'+left(convert(varchar,@DateType,21),7)+'-'+replace(right(str(@GetId),6),' ','0')
    update dbo.BillsID with (TABLOCKX) set MonthCount=@Getid where (BillsType=@billsType and MonthType=left(convert(varchar,@DateType,21),7))
    end 
    else
    begin
    set @GetId=@getid+1
    select @BillsType+'-'+left(convert(varchar,@DateType,21),7)+'-'+replace(right(str(@GetId),6),' ','0')
    INSERT INTO dbo.BillsID with (TABLOCKX) (BillsType,MonthType,MonthCount) VALUES (@BillsType,left(convert(varchar,@DateType,21),7),@GetId)
    end
    end
    
    if (@billsmode=2) 
    BEGIN
    if (exists(select ( BillsID.YearCount) from BillsID where BillsType=@billsType and YearType=left(convert(varchar,@DateType,21),4)))
    BEGIN
    select @GetId=BillsID.YearCount from BillsID where BillsType=@billsType and YearType=left(convert(varchar,@DateType,21),4)
    set @GetId=@getid+1
    select @BillsType+'-'+left(convert(varchar,@DateType,21),4)+'-'+replace(right(str(@GetId),8),' ','0')
    update dbo.BillsID with (TABLOCKX) set YearCount=@Getid where (BillsType=@billsType and YearType=left(convert(varchar,@DateType,21),4))
    end 
    else
    begin
    set @GetId=@getid+1
    select @BillsType+'-'+left(convert(varchar,@DateType,21),4)+'-'+replace(right(str(@GetId),8),' ','0')
    INSERT INTO dbo.BillsID with (TABLOCKX) (BillsType,YearType,YearCount) VALUES (@BillsType,left(convert(varchar,@DateType,21),4),@GetId)
    end
    end
    END
  • 相关阅读:
    【深入学习MySQL】MySQL的索引结构为什么使用B+树?
    【Python爬虫】爬了七天七夜,终于爬出了博客园粉丝数排行榜!
    【BAT面试题系列】面试官:你了解乐观锁和悲观锁吗?
    深入学习MySQL事务:ACID特性的实现原理
    深入学习Redis(5):集群
    深入学习Redis(4):哨兵
    谈谈微信支付曝出的漏洞
    深入学习Redis(3):主从复制
    深入学习Redis(2):持久化
    Spring中获取request的几种方法,及其线程安全性分析
  • 原文地址:https://www.cnblogs.com/Thenext/p/9690618.html
Copyright © 2011-2022 走看看