restrict the second user while updating the first user

restrict the second user while updating the first user

 

  

Hi

I wrote a stored procedure to generate slip no automatically. Then problem
is when multiple users update the same time sp will go for a toss. How I can
I restrict the second user while updating the first user.

Pls find the attached sp below

CREATE proc CMS_procActionCDSlipVerify
@BankSlipNo Varchar(15)='',
@GeneratedBy Varchar(20)='',
@RowIDs Varchar(500)=''
As
Begin

Set NOCOunt ON

--SET TRANSACTION ISOLATION LEVEL SERIALIZABLE

Begin Tran

Exec('Update CMS_CDSlipEntry
Set BankSlipNo = ''' + @BankSlipNo +
''', SlipNo = (Select Max(IsNull(SlipNo,0)) + 1 From CMS_CDSlipEntry )
, GeneratedBy = ''' + @GeneratedBy +
''', GeneratedDateTime = GetDate() ' +
' Where RowID In (' + @RowIDs + ')')

if @@Error <> 0
Rollback Tran
Else
Commit Tran

--SET TRANSACTION ISOLATION LEVEL READ COMMITTED

Set NOCOunt OFF

End





MS Sql Server LazyDBA home page