如何在日期更改时从sql数据库中生成1的数字 [英] How to generate number from 1 in sql databse when date change

查看:111
本文介绍了如何在日期更改时从sql数据库中生成1的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆