Click here to Skip to main content
16,022,828 members
Please Sign up or sign in to vote.
1.39/5 (7 votes)
how to reset bill no everyday in sql or c#


What I have tried:

with c# loop to check date every time, goes dirty.
Posted
Updated 18-Mar-18 7:48am
v2
Comments
CHill60 18-Mar-18 6:00am    
Please clarify your question and share the code you have tried. There is not enough information here for us to be able to help you

See answer here, it involves using a separate Thread that fires an event: c# wpf Datetime changed (New day has come) event - Stack Overflow[^]
 
Share this answer
 
If you would like to increase BillNo till next date in multi-user environ , i'd suggest to create computed column in your table, which will get SQL function as a formula. This function will get a date of sale as an input and return MAX(BillNo) +1. For example:
SQL
CREATE FUNCTION BillNumberForDate(@inputDate DATE TIME) RETURNS INT
AS
BEGIN
    DECLARE @bn INT = 0;
    SELECT @bn=COALESCE(MAX(BillNo), 0) + 1
    FROM YourTable
    WHERE CONVERT(DATE, SaleDate) = @inputDate
RETURN @bn
END;


How to add this function to computed column in your table? See: Formula For Computed Column Specification Property in SQL Server 2012[^]

For further details, please see:
CREATE FUNCTION (Transact-SQL) | Microsoft Docs[^]
Specify Computed Columns in a Table | Microsoft Docs[^]

Note:
I'd strongly advise you against to "produce" BillNo on client side for set of reason. For example: you'll get duplicated BillNos.
 
Share this answer
 
v3
Comments
Member 11797166 19-Mar-18 0:18am    
thanks Maciej Los
Maciej Los 19-Mar-18 1:01am    
You're very welcome.

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