偶有一个SQL语句:
select spbh,
 case 
  when (ascii(upper(substring(spbh,5,1)))>=65) and (ascii(upper(substring(spbh,5,1)))<=90 ) then
    SUBSTRING(spbh , 6 , 4) 
  else
    SUBSTRING(spbh , 7 , 4) 
  end as 顺序号
from spml order by 顺序号
该语句在SQL查询分析器里能正常执行的。这样的一个语句,我在DELPHI 里面用query1.SQL.Add里面用,发现老是执行不了,这里错那里错的,分好也都乱乱的不知道该怎么加了!问下有什么好的解决办法呢,能让SQL语句比较清楚呢 ! 
除了用存储过程之外的办法。

解决方案 »

  1.   

    Qry.close;
    Qry.sql.clear;
    Qry.sql.text := 'select spbh,
     case 
      when (ascii(upper(substring(spbh,5,1)))>=65) and (ascii(upper(substring(spbh,5,1)))<=90 ) then
        SUBSTRING(spbh , 6 , 4) 
      else
        SUBSTRING(spbh , 7 , 4) 
      end as 顺序号
    from spml order by 顺序号'Qry.execsql;
      

  2.   

    如果语句没错的话,或者做成存储过程,或者用Sql.Add方法的话就要细心检查了,要不然把这个句子先负值给一个字符串变量,在ADD进取,然后跟踪一下,看看结果。
      

  3.   

    Qry.close;
    Qry.sql.clear;
    Qry.sql.text := 'select spbh,
     case 
      when (ascii(upper(substring(spbh,5,1)))>=65) and (ascii(upper(substring(spbh,5,1)))<=90 ) then
        SUBSTRING(spbh , 6 , 4) 
      else
        SUBSTRING(spbh , 7 , 4) 
      end as 顺序号
    from spml order by 顺序号'Qry.Open;