将数据类型varchar转换为数值时出错

时间:2018-01-29 06:43:03

标签: sql sql-server-2008

我在执行此查询时遇到问题。

select 
CASE when (c.Rate=0.00) then a.Item else cast('N/A' AS DECIMAL(5,2))  end 
from item a join rate_m c on a.item=c.item where  a.item='0781718171'

当我执行此查询时,出现错误,

Msg 8114, Level 16, State 5, Line 4
Error converting data type varchar to numeric.

我尝试按照上面的方式进行投射,但没有成功。请帮助我,c.rate列创建为decimal(5,2)

如果c.rate is > 0.00

,我需要输出为N / A.

1 个答案:

答案 0 :(得分:0)

VARCHAR DECIMAL的价值不能CAST,但您可以DECIMAL VARCHAR重视SELECT CASE WHEN c.Rate>0.00 THEN 'N/A' ELSE CAST(a.Item AS VARCHAR) END FROM item a JOIN rate_m c ON a.item=c.item WHERE a.item='0781718171'

试试这个:

$content = file_get_contents("/tmp/some_file");
if($content === false){
    print_r(error_get_last());
}