原句是
select convert(varchar(5),convert(numeric(4,2),(Producth.QaNg2+0.05)/Producth.PlanQty*100))+'%'as SumRate from ......
在查询分析器中能够运行,并能得到正确结果,但要在外面加上引号后我就迷茫了?

解决方案 »

  1.   

    select cast((Producth.QaNg2+0.05)/Producth.PlanQty*100) as varchar(10))+'%' as SumRate from ......
      

  2.   

    改为:
    dateset.sql.add('Select cast((Producth.QaNg2+0.05)/Producth.PlanQty*100)) as varchar(20))+''%'' as SumRate from ......')
      

  3.   

    WangZWang(阿来) 的是对的,但我还是困惑,因为
    select plantqty from ...where productid='65423'不是要写成
    dateset.sql.add('select plantqty from ...where productid='''+'65423'+'''')吗?
    而不是dateset.sql.add('select plantqty from ...where productid=''65423'')呀!
      

  4.   

    改为:
    dateset.sql.add('Select cast((Producth.QaNg2+0.05)/Producth.PlanQty*100)) as varchar(20))+''%'' as SumRate from ......')
      

  5.   

    WangZWang(阿来) 的是对的,但我还是困惑,因为
    select plantqty from ...where productid='65423'不是要写成
    dateset.sql.add('select plantqty from ...where productid='''+'65423'+'''')吗?
    而不是dateset.sql.add('select plantqty from ...where productid=''65423'')呀!
      

  6.   

    楼主写的程序中的SQL语句中其实隐含这类型转换,
    即 (Producth.QaNg2+0.05)/Producth.PlanQty*100 是数值计算,
    而 + ‘%’之后变成了字符运算,
    而在DELPHI中程序,他最终被转化为 数值的计算了,所以出现错误了
      

  7.   

    我还是困惑,因为
    select plantqty from ...where productid='65423'不是要写成
    dateset.sql.add('select plantqty from ...where productid='''+'65423'+'''')吗?
    而不是dateset.sql.add('select plantqty from ...where productid=''65423'')呀!