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)
 Delete Query using convert in where condition for date

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-10 : 07:48:37
Siddhartha writes "Hi

I am having an unique problem, why i dont understand

I am using SQL Server 2000 wth SP3 on a Win2K Server.

I have a table (RR_IVR_STATISTICS) with several columns, the first 4 are

RR_DATE - datetime
RR_INTERVALSTARTTIME - datetime
RR_INTERVALSTOPTIME - datetime
RR_IF_ELEMENTUNIQUEID - varchar(50)

The table is clustered indexed with RR_INTERVALSTARTTIME (desc), RR_INTERVALSTOPTIME (desc), RR_IF_ELEMENTUNIQUEID (asc)

I just insert one row of data, the insert query is

Insert into RR_IVR_STATISTICS(RR_DATE,RR_INTERVALSTARTTIME,RR_INTERVALSTOPTIME,RR_IF_ELEMENTUNIQUEID.....) values(convert(varchar,'2005-07-28 15:24:00',20),convert(varchar,'2005-07-28 15:15:00',20),convert(varchar,'2005-07-28 15:30:00',20),'1_2_12_7002'.....)


If you notice the IntervalStarttime is on 28th of July.

Now i apply a select query and a delete query

select * from RR_IVR_STATISTICS where RR_INTERVALSTARTTIME < convert(varchar,'2005-07-25 00:00:00',20)

delete from RR_IVR_STATISTICS where RR_INTERVALSTARTTIME < convert(varchar,'2005-07-25 00:00:00',20)

Both the select and Delete Query have the same Where condition, that is delete data before 25th Of july.

===================
While the select Query does not return any Data, as it should not. But the Delete query deletes the row in the table even though the Where condition does not satisfy.
===================

The funniest part, If i change my clustered index from desc to asc for both the datetime fields.
The delete query as well as the select query works perfectly

Someone please help me in finding a solution to this problem and how is the index order related to the problem

Thanks

Sid
"
   

- Advertisement -