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:
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
BillNo
s.