开发者

Arithmetic overflow error converting varchar to data type numeric?

开发者 https://www.devze.com 2023-04-06 19:05 出处:网络
SELECT CASE Price WHEN \'\' THEN 0.0 ELSE Price END F开发者_运维问答ROM Table If price empty, it returns 0.0 but if column has value it gives me the error below
SELECT CASE Price WHEN '' THEN 0.0 ELSE Price END F开发者_运维问答ROM Table

If price empty, it returns 0.0 but if column has value it gives me the error below

Arithmetic overflow error converting varchar to data type numeric.

How to change my code to handle this case?


SELECT CASE Price WHEN '' THEN 0.0 ELSE CAST(Price AS DECIMAL(...)) END FROM Table

Implicit conversions will often take the smallest type possible, so when you hit a larger value it will fail. Explicitly convert/cast your value to the right type in your CASE/ELSE.

0

精彩评论

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