Click here to Skip to main content
16,019,055 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
please help me i have one table name is FeesReceipt (id,receiptNo)
i want to make stored procedure to generate receipt like R-04/023
where R for receipt
04 means month when creating (like here 04 is April )
023 means auto generate Numbers
Posted
Comments
[no name] 11-Apr-14 12:42pm    
Okay and what sort of help is it that you would need?
Rajnish D mishra 11-Apr-14 12:59pm    
how i generate month how to attached this month to as like R-04/23

Here is an idea: How to generate IDS like 0001,0002----0010[^].

Modify it to your needs.
 
Share this answer
 
Try this;

SQL
create table dbo.Receipts(
id int identity,
ReceiptNumber as ('R'+'-' + (right('0'+ convert(varchar(3),month(getdate())), 2) + '/' + '0' + convert(varchar,id, 0))),
Name varchar(20)
)
 
Share this answer
 
v2
 
Share this answer
 
Hi Rajnish ,

My idea is you may create and maintain one separate table for auto Generation purpose.
That auto gen table consists following columns -
generation prefix , generation suffix ,serial number ,maximum number and Default.
let me explain in your scenario.
Your's requirement - "R-04/023"

prefix - "R-"
default - "04/" (your month or year or anything else)
serial number - generation numbers( from 1 to maximum number value in table)
suffix - it may require in some other scenario.


I hope you understand.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900