生成单据编号的存储过程

复制代码
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:\Users\admin\AppData\Local\Temp\~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
复制代码

 

posted @   Thenext  阅读(388)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示