with ADOQuery_shijuan do         { 统计程序设计题}
        begin
        close;
        sql.clear;
        sql.add('insert SJTJ(tx,DJ,sjks,sjjx)');
        sql.add('select 'CXSJ-'+case substring(SJBH,1,1)');
        sql.add('when ='1' then 'C'' );
        sql.add('when ='2' then 'C++'');
        sql.add('when ='3' then 'foxpro'');
        sql.add('when ='4' then 'pascal'');
        sql.add('when ='5' then 'VB'');
        sql.add('when ='6' then 'VF'');
       end;
            sql.add('substring(SJBH,2,1),sjks=min(STH),sjjx=max(STH)' );
            sql.add('from CXSJ');
            sql.add('(group by case substring(SJBH,1,1)' );
            sql.add( 'when ='1' then 'C'');
            sql.add( 'when ='2' then 'C++'' );
            sql.add('when ='3' then 'foxpro'');
            sql.add('when ='4' then 'pascal'');
            sql.add(' when ='5' then 'VB''  );
            sql.add('sql.add(sql.add( when ='6' then 'VF'');
        end;
        sql.add('substring(SJBH,2,1)');
        sql.add('union all');
        end;

解决方案 »

  1.   

    with ADOQuery_shijuan do         { 统计程序设计题}
            begin
            close;
            sql.clear;
            sql.add('insert SJTJ(tx,DJ,sjks,sjjx)');
            sql.add('select ' + QuotedStr('CXSJ-') + ' case substring(SJBH,1,1)');
            sql.add('when = ' + QuotedStr('1') + ' then ' + QuotedStr('C'));
            sql.add('when = ' + QuotedStr('2') + ' then ' + QuotedStr('C++'));
            sql.add('when = ' + QuotedStr('4') + ' then ' + QuotedStr('pascal'));
            sql.add('when = ' + QuotedStr('5') + ' then ' + QuotedStr('VB'));
            sql.add('when = ' + QuotedStr('6') + ' then ' + QuotedStr('Vf'));
           end;
    其余同理 。。
      

  2.   

    好麻烦!
    首先单引号错误不少
    用存储过程挺好的
    另外可考虑用主从表,把‘C', 'C++', 'Delphi'等放到从表中,
    用JOIN与主表连接