Generating next transno from last transno as per transtype

eshack

Member
Joined
Jul 3, 2011
Messages
7
Programming Experience
Beginner
I have details view with colum INVH_NO, INVH_TXN_TYPE, INVH_CUST_CODE, INVH_DT.
I want to update INVH_NO as the Last No+1 as new number as per INVH_TYPE when inserting new record;
When I went some forums i read suggestions as write procedure ;which i understand like this ; not sure it is complete and correct

Alter Procedure SP_nextTranNo
@TransType varchar(10)
@ NextNo int output

As
Begin
Select Top 1 INVH_No from OT_INVOICE_HEAD where INVH_TXN_CODE=@TRANSTYPE ORDER BY INVH_NO DESC
End

If all the syndex are correct it should return the last INVH_NO as per parameters passed.
( When I tested with MS SQL SERVER MANAGEMENT -Execute query: Select TOP 1 from OT_INVOICE_HEAD where INVH_TXN_CODE='FEES' ORDER BY INVH_NO DESC ----lists last invoice no as per FEES))

Now how I complete the stored procedure as per correct syntex - help to write this procedure
When and how (which event) to call this procedure in Details view - help to call this procedure and pass the parameter from input value INVH_TXN_CODE
How I can bind this output+1 to INVH_NO - help me to bind the value to DATA field
MY understanding is it must be done while updating?? as final step as data updating in table.

Thanks for your time and support
 
I wrote the following stored procedure to read the last transaction number and added +1 as my new transaction no.

Thanks for everyone trying to help me
ALTER PROCEDURE [dbo].[SP_NEWTRANNO]


@INVH_TXN_CODE VARCHAR(12),
@INVH_DT DATE,
@INVH_CAL_PERIOD Int,
@INVH_NO Int,
/*** INVH_NO parameter is passed but not used as selected from last no ****/
@INVH_REF_NO int,
@INVH_CUST_CODE VARCHAR(20),
@NEWNO int output


AS
Select Top 1 @NEWNO =INVH_NO from OT_INVOICE_HEAD where INVH_TXN_CODE=@INVH_TXN_CODE order BY INVH_NO DESC
INSERT INTO OT_INVOICE_HEAD (INVH_TXN_CODE,INVH_DT,INVH_CAL_PERIOD,INVH_REF_NO,INVH_CUST_CODE,INVH_NO)
VALUES(@INVH_TXN_CODE,@INVH_DT,@INVH_CAL_PERIOD,@INVH_REF_NO,@INVH_CUST_CODE,@NEWNO+1)
 
Back
Top