I have a table with two columns - ID as int and date stored as nvarchar for some reason.
A non-clustered index was recently created on the ID field. Now in my query, when I convert the date from nvarchar to date, it gives me an 'Arithmetic overflow error converting expression to data type datetime.' exception.
If I remove the id field from my query, the conversion works perfectly. Similarly if I remove the date field conversion from my query, it again works perfectly. If I drop the index, the original query works perfectly.
My question now is, why is an index on an ID column messing up conversion in a what-I-think-as-unrelated, date column?
Any explanation on this is much appreciated. And Query is:
select e.date ,e.id as id from dbo.table1 e,dbo.table2 d with (nolock)
where e.id=d.id and
convert(datetime,e.date) between convert(datetime,'07/01/2012')
and convert(datetime,'07/02/2012') group by e.date,e.id