Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transferring character field into numeric field
Message
De
22/10/2012 11:09:22
 
 
À
22/10/2012 10:01:51
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01555436
Message ID:
01555454
Vues:
48
This message has been marked as a message which has helped to the initial question of the thread.
>>1e5 or 1d4 should be treated as numeric by isnumeric function. In fact, Sergey has a blog on this very topic
>>http://berezniker.com/content/pages/sql/microsoft-sql-server/isnumericex-udf-data-type-aware
>
>This is a sophisticated technique. Thanks for the reference
>
>However, this one also uses the WHERE approach. Thus, all records not eligible will not be taken into consideration. I am looking at including all records but to convert the non numeric values from the character field into 0, when this is not something that SQL Server could convert. I do not know if that is possible.


Use CASE :
SELECT ...
       CASE WHEN ISNUMERIC(YourField+'e0') = 1
                 THEN CAST(YourField as Numeric(xx, yy)
            ELSE 0 END AS YourNumberField
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform