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
 General SQL Server Forums
 New to SQL Server Programming
 DateTime Conversion

Author  Topic 

planetoneautomation
Posting Yak Master

105 Posts

Posted - 2012-11-13 : 15:48:30
In my SELECT clause I have:

MAX(RN_EXECUTION_DATE) AS 'MAXDATE',
MAX(RN_EXECUTION_TIME) AS 'MAXTIME',


... and in my WHERE clause I have:
RN_EXECUTION_DATE = 'MAXDATE' AND
RN_EXECUTION_TIME = 'MAXTIME'


When executed, I get "Conversion failed when converting date and/or time from character string".

I looked at using CONVERT but can't seem to make it work. And, is it the 'MAXDATE' and 'MAXTIME' from the SELECT clause that needs conversion? Or is it something in the WHERE clause?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-11-13 : 15:50:51
MAXDATE/MAXTIME in your SELECT are just aliases. The WHERE clause is why you are getting that error. You can't specify the MAXDATE/MAXTIME aliases as that's where data goes. If you want it equal to MAXDATE/MAXTIME, you'll need a subquery.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -