Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Recently my boss asked me to create a functionality where the number of orders for a particular payment slip increments with the slip number. It is something like this:
If my invoice slip number is 12 and it has multiple orders so the number of orders should be like this - 1201, 1202, 1203 ....and so on.
How can i create a method which first time picks the invoice number from data base and add o01 at its end. And then for next time always it should inc the order number automatically. I have a idea in my mind where i can inc the invoice number by 01 but how to make sure it goes for the first time only. for all other times the existing work order numb should be increased. ?
Please suggest a idea.
Posted

1 solution

In my opinion this is something you should do when you query the data and you should not store that information in the database. The numbers may change if records are deleted, added between other records and so on. Calculated items shouldn't be generally stored.

To get the ordinal number in a query you can use ROW_NUMBER [^]

Depending on the situation you can get the slip number and the row number in separate columns and format them at client side (concatenate etc). Of course they can be converted to character and concatenated in the SQL statement but typically formatting shouldn't be done with SQL
 
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