I'm developing a c# application that consists of Document Incoming System for my police station.
In this system, variable document's contents are been saved to an SQL database. I must give them a "Document Number".
I'm achieving all of these, but i want that every years last day such as 31.12.2014
, the numbers that have been given to a document like "2145" will turn to "1" at the the first day of year 01.01.2015
.
So, the records must be 2014/2145
. and the last days of years turns to 2015/1
.
How can I achieve this?
You count the existing documents for the same year, then add one.
So if you want to store a document that belongs to 2013, you first count how many existing documents you have in 2013, then add one.
I can't write the sql for you, because you haven't described the data structure, but it should be simple enough using SQL COUNT
, and DATEPART
to retrieve only the year from a date field.