tsql - MS SQL server casting without exception -


Is there any "convert" function in MS SQL server that allows to type the type securely (throwing exceptions Without) I want something like "tryParsse" in C #Lang, but as the SQL statement.

More detailed, I need to leave zero or some other of the following statement, but throw exceptions.

Select

P> P> This will make non-numerics default to 0 and no other statement will be required:

 Select  when ISGLEERIC (myvarcharcolumn) = 1 then convert (float, replace (  

The REPLACE () function call is used to convert a comma to a period. In some cultures, the decimal separator (e.g., instead of "1.25" "1,25"), but when That your server does not set any one of these as the default culture, will return ISLDERIC (1), but convert it to an error; does mean that your Strings should not use commas as thousands of isolation, but in most cases, a comma for a decimal placeholder is more likely to be a decimal placeholder.

LTRIM (RTRIM ()) Call because ISLDERIC() Returns 1 for the string with leading or trailing spaces, but Convert () can not deal with them. Therefore, you have to trim your stars.

The only remaining potential problem is that ISLDERIC () back 1 if the number can be displayed in the form of an integer, currency, decimals, or float, but you actually convert only to a float, in fact Floats can store anything about whatever you throw at it, but if you are trying to convert it to an intern instead, then ISLINKERIC () returns a value like "2.5" for the value, but the convert ( Int, '2.5') still a Throw error.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -