每两小时从表中获取数据 [英] Fetching data from table every two hours

查看:70
本文介绍了每两小时从表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Iam尝试从我的表中获取最后更新的记录。它必须每两小时取一次。如果两小时后没有数据更改,那么我们必须显示之前的数据我已经编写了存储过程,但它没有工作。在尝试执行查询时,Iam给DateToday和DateNextDay,持续时间为2小时,可以在数据库中找到。任何人都可以帮助查找查询中的错误。或者还有其他最好的方法吗?



Hi,
Iam trying to fetch the last updated record from my table.And it has to fetch every two hours.If no data is changed after two hours then we have to display the earlier data.I have written the stored procedure but it is not working.While trying to execute the query,Iam giving DateToday and DateNextDay with a duration of 2 hours which is available in the database.Can anyone help to find out the fault in the query.Or is there any other best way to do this?

ALTER PROCEDURE [dbo].[TwoHour_BalanceUpdate] 
	-- Add the parameters for the stored procedure here
	@ConsumerCode varchar(50),
	@DateToday datetime ,
    @DateNextDay datetime
    
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	select CURRENT_BALANCE from dbo.tbl_deposit where ID = (SELECT MAX(ID) FROM dbo.tbl_deposit) and ConsumerCode=@ConsumerCode and dbo.tbl_deposit.DEPOSIT_DATE between @DateToday and @DateNextDay
END

推荐答案

您好Aarti



As根据我的理解,你想定期运行SP 2小时...对吗?



那么为什么不使用Job Scheduler呢。我在下面添加了一些链接,这将指导如何在SQL代理作业中执行存储过程?

http://stackoverflow.com/questions/1216272/how-to-execute-a-stored-procedure- in-a-sql-agent-job [ ^ ]



http://blog.sqlauthority.com/2011/05/23/sql-server-running-ssis- package-in-scheduled-job / [ ^ ]



我希望它会对你有所帮助...新年快乐......祝你好运..



问候,

Vijay
Hi Aarti

As per my understanding, you want to run a SP 2hrs regular intervals ... Right ?

So why don''t u use Job Scheduler for that. I added few link below this will guide
u how to execute a stored procedure in a SQL Agent job?
http://stackoverflow.com/questions/1216272/how-to-execute-a-stored-procedure-in-a-sql-agent-job[^]

http://blog.sqlauthority.com/2011/05/23/sql-server-running-ssis-package-in-scheduled-job/[^]

I hope it will help u... Happy New Year ... Wish you good luck..

Regards,
Vijay


hi

只需按此...



http://blog.sqlauthority.com/2011/05/23/sql-server-running-ssis-package-in-scheduled- job / [ ^ ]



并使用上一个链接。:)





问候,

Vijay
hi
Just go with this ...

http://blog.sqlauthority.com/2011/05/23/sql-server-running-ssis-package-in-scheduled-job/[^]

and use the previous link.:)


Regards,
Vijay


这篇关于每两小时从表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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