Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 4th, 2006, 10:06 AM
corellana6 corellana6 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 2 corellana6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 23 sec
Reputation Power: 0
SQL Job datetime comparison problem

Hi, my problem is the following.

I have a stored procedure that runs the following t-sql:

delete MYTABLE
where DATETIMECOLUMN < dateadd(day,-29,getdate())

If I run this from Query Analizer with EXEC, it works fine.

When I run this as a scheduled job it deletes all rows where the date is AFTER dateadd(day,-29,getdate()), which is wrong. The strange thing is, the same scheduled job run on another server works fine.

I know Server Agent stores some of its dates in another format. But is this related, ¿why does it work in the other server?

Any help appreciated.
Cristian

Reply With Quote
  #2  
Old July 4th, 2006, 01:20 PM
corellana6 corellana6 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 2 corellana6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 23 sec
Reputation Power: 0
More info

Actually the problem is really this:

1. I open query analizer and connect to a DB server on another IP in the same network.

2. I execute the following statements on a table that has a clustered index (descending) on the column that appears in the where clauses.

select * from MYTABLE
where DATETIMEFIELD < dateadd(day,-29,getdate())

delete MYTABLE
where DATETIMEFIELD < dateadd(day,-29,getdate())

3. The funny thing is, the above commands do not affect the same rows!

4. If I take away the index, the both commands affect the same rows.

5. The same work fine on another server (with the index).

Thanks for any comments.
Cristian

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > SQL Job datetime comparison problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway