Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating a numeric field with a character field
Message
 
 
To
29/10/2014 10:36:31
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01610090
Message ID:
01610100
Views:
39
This message has been marked as a message which has helped to the initial question of the thread.
>>It should unless you have not numeric data. What error do you get?
>
>After verification, while the command to CAST as INT would work, one of the records has a special character in it, probably an error in the code at some time, which allowed non numeric value to be entered in that field. So, I would need to look for a more enhanced command to convert only numeric values, and if a non-digit character is found in the field, to consider that as 0.

Use ISNUMERIC() function
UPDATE Client SET Amount2 = 
CASE WHEN ISNUMERIC(Amount ) = 1 THEN CAST(Amount AS INT) ELSE 0 END)
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform