一个 自动生成ID 但是 没有做到完全自动话 。。考虑中

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

 

 


ALTER proc [dbo].[BM_GetNumber_Mange]
@BMI_ID varchar(14)
as
declare  @isnull  int
set @isnull=(SELECT  count(*)FROM         BP_ManageIssue INNER JOIN
                      FlowDataV ON BP_ManageIssue.BMI_ID = FlowDataV.MFI_DataID
WHERE     (NOT (FlowDataV.FlowFinish IS NULL)) AND (BP_ManageIssue.BMI_ID = @BMI_ID))
declare  @num varchar(20)
declare  @count int
set @count =(select count(*) from BP_ManageIssue where BMI_Year=datepart(year,getdate()))
begin
if(0<>@isnull)
begin
if(0=@count)
begin
update  BP_ManageIssue  set BMI_Year=datepart(year,getdate()),BMI_Character='中咨计便字'+'['+cast (datepart(year,getdate()) as varchar )+']'+'01'+'号' where BMI_ID=@BMI_ID
end
else if(0<@count and 10>@count)
begin
set @num=(select '0' + cast((select count(*)+1 from BP_ManageIssue where BMI_Year=datepart(year,getdate())) as varchar))
update  BP_ManageIssue  set BMI_Character='中咨计便字'+'['+cast (datepart(year,getdate()) as varchar )+']'+@num+'号', BMI_Year=datepart(year,getdate()) where BMI_ID=@BMI_ID
end
else
begin
set @num=(select count(*)+1 from BP_ManageIssue where BMI_Year=datepart(year,getdate()))
update  BP_ManageIssue  set BMI_Character='中咨计便字'+'['+cast (datepart(year,getdate()) as varchar )+']'+@num+'号', BMI_Year=datepart(year,getdate()) where BMI_ID=@BMI_ID
end
end
end

你可能感兴趣的:(生成)