I am creating a windows application using c#.net 2010, How to reset invoice number at the beginning of the financial year using SQL server 2008
This is my query
SQL
select isnull(max(billnu),0) +1 from sales where saldate between CAST('04/01/'+ CAST(YEAR(GETDATE())as varchar) as DateTime) and CAST('03/31/'+ CAST((YEAR(GETDATE())+ 1) as varchar)as DateTime)but the invoice number displays 1, last year I am done with more than 100 bills. Please any one solves my problems.

Amit MohantyRank #112 · 20K reputationPosted Jan 9, 2023, 11:50 PM EST
Create a table to store the current invoice number. This table should have at least two columns: one for the financial year (e.g., 2021, 2022) and one for the current invoice number.
CREATE TABLE InvoiceNumbers ( Year INT NOT NULL, Number INT NOT NULL );Insert a row into the table for the current financial year, with the invoice number set to 1.
INSERT INTO InvoiceNumbers (Year, Number) VALUES (2022, 1);When you need to generate a new invoice number, select the current number from the table and increment it by 1. Then, update the table with the new number.
UPDATE InvoiceNumbers SET Number = Number + 1 WHERE Year = 2022;This method allows you to reset the invoice number to 1 at the beginning of each financial year by simply inserting a new row into the table with the current year and a number of 1.