如何在日期更改时从sql数据库中生成1的数字 [英] How to generate number from 1 in sql databse when date change
问题描述
我在ado项目中有一个customer_of_today列,它存储了客户的总数,我希望存储当天最后一个客户的序列号。第二天它也应该从1开始。每天都应该遵循同样的进展。我该怎么办,请帮助我
SHOUTING删除 - OriginalGriff [/ edit]
< blockquote>示例存储过程:
CREATE PROCEDURE GetClientIDForDay()
AS
BEGIN
DECLARE @ aDay DATE
DECLARE @ CId INT
SET @ aDay = GETDATE()
SELECT @ CId = MAX( COALESCE ([customer_of_today], 0 ))
FROM YourTable
WHERE [SalesDate] = @ aDay
RETURN @ CId
结束
可能您需要根据客户编号进行查询。
< blockquote>
在将条目保存到数据库之前,获取当天条目的计数,在google上查看SQL COUNT。当您获得所选日期数据库中的条目数时,请在新条目上使用(count + 1)作为序列号。
SELECT COUNT(Datecolumn) FROM 客户 WHERE DateColumn = ' 2013-03-05'
希望这会有所帮助。
问候
Jegan
i have a column customer_of_today in ado project it store total number of customer, i want to store serial number from 1 upto last customer of the day. And next day it should also start from 1. And every day this same prosess should be follow. What should i do, plz help me
[edit]SHOUTING removed - OriginalGriff[/edit]
Example stored procedure:
CREATE PROCEDURE GetClientIDForDay() AS BEGIN DECLARE @aDay DATE DECLARE @CId INT SET @aDay = GETDATE() SELECT @CId = MAX(COALESCE([customer_of_today],0)) FROM YourTable WHERE [SalesDate] = @aDay RETURN @CId END
Probably you need to make query conditional on customer number.
Hi,
Before you save entries into database, get the count of the entries for that day, check on google for "SQL COUNT". when you get the count of entries in the db for that selected day, use (count + 1) as your serial number on the new entry.
SELECT COUNT(Datecolumn) FROM Customers WHERE DateColumn='2013-03-05'
Hope this helps.
Regards
Jegan
这篇关于如何在日期更改时从sql数据库中生成1的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!