如何在SQL或C#中每天重置账单 [英] How to reset bill no everyday in SQL or C#
问题描述
how to reset bill no everyday in sql or c#
我尝试过:
用c#循环每次检查日期,变脏。
What I have tried:
with c# loop to check date every time, goes dirty.
推荐答案
参见回答这里,它涉及使用单独的线程来触发事件: c#wpf日期时间已更改(新的一天到来)事件 - 堆栈溢出 [ ^ ]
See answer here, it involves using a separate Thread that fires an event: c# wpf Datetime changed (New day has come) event - Stack Overflow[^]
如果你想增加BillNo
直到多用户环境中的下一个日期,我建议在你的表中创建计算列,这将获得SQL函数作为公式。此功能将获得销售日期作为输入并返回MAX(BillNo)+1
。例如:
If you would like to increaseBillNo
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 returnMAX(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;
如何将此函数添加到表中的计算列?请参阅:计算列规范属性的公式SQL Server 2012 [ ^ ]
详情请见:
CREATE FUNCTION(Transact-SQL)| Microsoft Docs [ ^ ]
在表中指定计算列Microsoft Docs [ ^ ]
注:
我强烈建议你不要生产出于原因,客户端 BillNo
。例如:你将得到重复的 BillNo
s。
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.
这篇关于如何在SQL或C#中每天重置账单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!