Thursday 15 May 2014

sql server 2008 - sql - conversion error when changing 'and' to 'or' -


I have database tables in SQL Server 2008. My query is breaking for a reason I do not know:

  select release_id, url_id, tt_projectid, release_title, tech_area, current_state, DATEADD (ss, last_built, '12 / 31 / Auto_integ_count & gt; 0 and MONTH (last_auto_integ) = '1' and YEAR (last_auto_ignage) as the last_auto_tate As force_count, transition_only_count, auto_integ_count, last_auto_intage, date (SS, Integ_company_date, '12/31/199620:00:00 ')) =' 2013 'and (release_id> 36000) order release_id desc < / Code> by  

its The version of the query works fine, but when I change the last line to 'and' to 'and' I get this conversion error:

  date from the conversion string And / or failed to change the time.   

Why am I changing

 as amazed 'and (release_id> 36000)'   < P>  
  'or (release_id> 36000)'   

is caused by such an error

The reason for this is because last_auto_integ is being stored as a string instead of a date. is not being executed with the and in the section - by way of it - because no one else happens when release_id & gt; 360000 .

From what I can see, there are no other places in the query where you can be converted to a string for a date format.

You can identify values ​​using these:

  Select last_auto_integ from tablename where isdate (last_auto_integ) = 0 and last_auto_integ is not empty  < / Pre> 

You can correct this problem in question by using case :

  where month (case when it's last (last_at_ttega) = 1 then Last_ito_integ end) = 1 and year (case when the horoscope (last_real_text) = 1 then last_auto_integ end) = 2013   

Or, you can only enter substring () and he The Sh can use to extract that you are using.

No comments:

Post a Comment