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
 SQL Server Development (2000)
 Convert in WHERE clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-05-04 : 08:29:29
Phaedo writes "OS: NT 4.0 Server
SQL 7.0 SP2

Are there known issues using convert in a where clause? I have two queries below, both using convert (from varchar to datetime) on the same field. The first works, the second returns the following error: 'Syntax error converting datetime from character string.'

'myField' is a varchar field that contains both convertable dates as well as other non-date strings. I searched the site, and the only items I found that were even close regarded the format of the string being converted. It doesn't appear that that is the case here since the first query works. Have you seen anything like this before? Is it merely a result of how the Where selection criteria is processed?

Thanks.


Works:

SELECT convert(datetime, myField) FROM myTable
WHERE [criteria to get entries that have date in myField]


Does not work:

SELECT * FROM myTable
WHERE [criteria to get entries that have date in myField]
AND convert(datetime, myField) < GetDate()"
   

- Advertisement -