Wednesday 15 May 2013

sql server - Getting conversion failed error even when CONVERT function is not being called SQL -


I use this command to select all the commands if the given variable is the date, if it is not, So it should return all fields.

When a date occurs in the form of a code, the @query command works, but it returns an error:

"The conversion failed

Code:

Edit:

There may be a string for @query Like "1/1/2013", "random", "3".

If there is no @query in the form of a date, the command will be all fields

You can solve this problem by remodeling your query status: Select varchar (20) = 'Blah' as ​​the quality of the declaration @ *

  declare @ where the ISDAT (@ value) = 0 or from the testlet = 0 or convert (date, date wise) = case ISDT ( @ Quality) when 1 mod By the time the tariff (date, @ quality) this problem is that the logic operator does not have short circuits in SQL, so the adapter  convert (date, @ some)      

/ code> is something that can pre-calculate the query for speed. By increasing the status for CASE , which relies solely on @query , you can terminate the execution of the CONVERT branch When ISDATE (@ query) returns "false".

No comments:

Post a Comment