PDB
PDB

Reputation: 103

Arithmetic overflow error converting expression in to data type datetime

Hoping someone can help. I've looked on the internet for a solution but none seem to resolve it.

I want to query a large table and only get the results back where a column equals today's date.

Here's the query:

select [Table1].[Field1]
from [Table1]
where [Table1].[Field1] = GetDate()

The date format is as follows:

 20020630

I'm a beginner in SQL so any help would be really appreciated because I am growing fond of it.

Thank you!!! :)

Upvotes: 0

Views: 1723

Answers (1)

gbn
gbn

Reputation: 432271

To find the broken value:

select [Table1].[Field1]
from [Table1]
where ISDATE([Table1].[Field1]) = 0

GETDATE includes a time, so you need to remove this. This assumes SQL Server 2008+

select [Table1].[Field1]
from [Table1]
where [Table1].[Field1] = CAST(GetDate() AS date)

Upvotes: 1

Related Questions