开发者

Error converting data type varchar to numeric

开发者 https://www.devze.com 2022-12-24 02:24 出处:网络
Update table set Test = C开发者_运维技巧onvert(varchar(53), Cast(Phone_Number as Decimal))if Phone_Number has any alphabetic or symbol characters it will fail when CASTing it to DECIMAL:

Update table set Test = C开发者_运维技巧onvert(varchar(53), Cast(Phone_Number as Decimal))


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
...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号