Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 If date statment.

Author  Topic 

michael_dms
Starting Member

2 Posts

Posted - 2011-01-26 : 17:44:30
I have a small SQL database which i use to update a screen in our telesales office with numbers of queued calls and missed called.

the table (named phone) is made up of three columns, missed, queue and date.

the table is updated by our voicemail system via an update query, this works fine. However i have to reset the values to zero each morning.

i want to change the update query so that is reads the date from the date column compares it to todays date and then clears both of the columns and starts again.

here is what i have,


declare @todaydate DATETIME SELECT DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 0) as todaydate
declare @testdate DATETIME select date from phone
if @testdate <> @todaydate
BEGIN
update phone set date = DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 0)
update phone set missed = 1
END
else
BEGIN
update phone set missed = missed+1
END



as far as i can see this should work, it will output the dates correctly but doesnt seem to compare them.

also will this query work with SQL 2008, we are getting a new server next month and it will have 2008 on.

Any help will be appreciated.

Regards

X002548
Not Just a Number

15586 Posts

Posted - 2011-01-26 : 18:05:35
are you concerning yourself with the time component?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

michael_dms
Starting Member

2 Posts

Posted - 2011-01-26 : 18:07:59
i need to disregard the time component as the updates can happen at any time of day. so when the first update happens it will clear the database and start from 1

Thanks
Go to Top of Page
   

- Advertisement -