如题, 怎样在一个TQuery 中写多条SQL 语句例: 数据库中可以写成
                    delete from X  where a=:a
                    /
                    delete from Y  where a=:a
                    /
                    delete from Z  where a=:a    请问在 TQuery 的SQL 中 想要实现这样的功能要怎样做?

解决方案 »

  1.   

    adoquery1.SQL.Add('delete from a where a=''1''');
    adoquery1.SQL.Add('delete from a where a=''2''');
    adoquery1.SQL.Add('delete from a where a=''3''');
    ADOQuery1.ExecSQL;
      

  2.   

    mssql支持多个sql语句一次提交的你有参数,而且是同一个参数名,那样是不行的
      

  3.   

    估计楼主的处理办法欠周到。但目的就是想删除三个表中符合条件的记录。
    可以参考以下二种方法: (1)利用存储过程  
     (2)在客户端         
            with adoquery1 do begin
             close;sql.clear;
             sql.add('delete from :aTableName where a=:aParm ');
             parameters.paramByName('aTableName').value:=aTb1;
             parameters.paramByName('aParm').value     :=aPm1;
             execsql;close;
             parameters.paramByName('aTableName').value:=aTb2;
             parameters.paramByName('aParm').value     :=aPm2;
             execsql;close;
             parameters.paramByName('aTableName').value:=aTb3;
             parameters.paramByName('aParm').value     :=aPm3;
             execsql;close;           
           end; 
      

  4.   

    begin tran
    delete from X  where a=:a 
                        / 
                        delete from Y  where a=:a 
                        / 
                        delete from Z  where a=:a commit tran
      

  5.   

    这得看数据库,对于sqlserver可以直接添加多条sql语句,对于access只能是一条
      

  6.   


    adoquery1.SQL.Add('delete from a where a in(''1'', ''2'', ''3'''); 
    ADOQuery1.ExecSQL; 
      

  7.   

    delete from X  where a=:a;delete from Y  where a=:a;delete from Z  where a=:a;
    這樣就可以執行的
      

  8.   

    事务管理吧,
    有些情况下,在sql语句后加特殊符号也行,比如分号";"什么的
      

  9.   

    adoquery1.SQL.Add('delete from a where a=''1''');
    adoquery1.SQL.Add('delete from a where a=''2''');
    adoquery1.SQL.Add('delete from a where a=''3''');
    ADOQuery1.ExecSQL;  这么写是不对的,Sql-Server数据库是支持多条语句的,但 adoquery里面这么写是不对的。 还是写个存储过程吧,如果只是执行连续的delete 语句,不想写存储过程,可以用 AdoCommand,不要用ADOquery
      

  10.   

      with AdoCommand1 do
      begin
        CommandText := 'delete from OrderList where id<50';
        Execute;
        CommandText := 'delete from OrderList where id<100';
        Execute;
        CommandText :=' delete from OrderList where id<200';
        Execute;
      end;
     测试了一下,这么写没有问题的!