Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

SQL
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
Posted
Updated 25-Dec-12 18:34pm
v2

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
 
Share this answer
 
Comments
danil33 26-Dec-12 2:00am    
Hi Vijay,
Thanks for your reply.The mentioned method I already saw.But in my sql server2008.In the Object Explorer->Management no provision for job scheduling can be seen.How can I take that.Please reply.
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900