실용적인 은행 이체 저장 과정과 흐름 번호 생성 저장 과정

2209 단어
은행 이체 저장 과정

USE [BankInfor]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Transfer](@inAccount int,@outAccount int,@amount float)
as declare
  @totalDeposit float;
  begin
  select @totalDeposit=total from Account where AccountNum=@outAccount;
  if @totalDeposit is null
  begin
  rollback;
  print'               '
  return;
  end
  if @totalDeposit 
 

흐름 번호 생성 저장 프로세스

if exists(select 1 from sysobjects where id=OBJECT_ID('GetSerialNo') and xtype='p')
drop proc GetSerialNo
go
Create procedure [dbo].[GetSerialNo]  
(  
  @sCode varchar(50)  
)  
as 
begin 
 Declare @sValue varchar(16),@dToday  datetime,@sQZ varchar(50) --       
  Begin Tran   
  Begin Try  
   --       ,    lock  ,          update     
  --       ,   update          
  Update SerialNo set sValue=sValue where sCode=@sCode  
  Select @sValue = sValue From SerialNo where sCode=@sCode  
  Select @sQZ = sQZ From SerialNo where sCode=@sCode  
   --         ,       
   If @sValue is null  
   Begin 
    Select @sValue = convert(bigint, convert(varchar(6), getdate(), 12) + '000001')  
    Update SerialNo set sValue=@sValue where sCode=@sCode  
   end else  
   Begin        --          
    Select @dToday = substring(@sValue,1,6)  
    --      ,  1  
    If @dToday = convert(varchar(6), getdate(), 12)  
     Select @sValue = convert(varchar(16), (convert(bigint, @sValue) + 1))  
    else       --       ,      ,    1    
     Select @sValue = convert(bigint, convert(varchar(6), getdate(), 12) +'000001')  
   Update SerialNo set sValue =@sValue where sCode=@sCode  
   End 
  Select result = @sQZ+@sValue   
   Commit Tran  
  End Try  
  Begin Catch  
   Rollback Tran  
   Select result = 'Error' 
  End Catch  
end 
select*from SerialNo
select convert(varchar(6), getdate(), 12)+'000001'

좋은 웹페이지 즐겨찾기