Update table set Test = Convert(varchar(53), Cast(Phone_Number as Decimal))
+3
A:
if Phone_Number has any alphabetic or symbol characters it will fail when CASTing it to DECIMAL:
Update table set Test = Convert(varchar(53), Cast(Phone_Number as Decimal))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Your question is very vague, but you could try:
Update YourTable
SET Test=CASE
WHEN ISNUMERIC(Phone_Number)=1 THEN Convert(varchar(53), Cast(Phone_Number as Decimal)) --this is your code unchanged
ELSE Phone_Number
END
...
KM
2010-03-23 17:18:22
If the UPDATE is for every row in the table (example code does not have a WHERE), then if only one `Phone_Number` has a bad character the entire UPDATE will fail. Run `SELECT * FROM YourTable WHERE ISNUMERIC(Phone_Number)=0` to find all the "bad" rows.
KM
2010-03-23 17:25:48