sql.Add('SELECT * FROM Student WHERE studentno in ');
sql.Add('(select studentno from score where Math between 60 and 85)' );
把以上语句改为带以下参数的应该怎么写?
var
KM,CJD:String;
KM:='Math';
CJD:='60 and 85';

解决方案 »

  1.   

    sql.text := 'SELECT * FROM Student WHERE studentno in (select studentno from score where '+QuotedStr(KM)+'between'+QuotedStr(CJD)+')'';
      

  2.   

    sql.text := Format('SELECT * FROM Student WHERE studentno in (select studentno from score where %s between %s ',[KM,CJD]) ;
      

  3.   

    SELECT * FROM Student as a,score as b WHERE a.studentno=bstudentno and b.km=''Math''  and b.CJD between 60 and 85
    试试看?
      

  4.   

    SELECT * FROM Student as a,score as b WHERE a.studentno=b.studentno and b.km=''Math''  and b.CJD between 60 and 85
      

  5.   

    sql.text := Format('SELECT * FROM Student WHERE studentno in (select studentno from score where %s between %s ',[KM,CJD]) ;-----------------------------------------------------------------------------------------
    sql.text := 'SELECT * FROM Student WHERE studentno in (select studentno from score where '+KM+'between'+CJD+')'';
      

  6.   

    不可能,有什么错误提示?? SQL语句是没有错的
      

  7.   

    sql.text := 'SELECT * FROM Student WHERE studentno in (select studentno from score where '+QuotedStr(KM)+'between'+QuotedStr(CJD)+')'';
      

  8.   

    正解://如果我没有搞错你的意思的话。
    var
      KM,CJD : String;
      sSql   : String;
    begin
      KM  := 'Math';
      CJD := '60 and 85';
      sSql := 'SELECT * FROM Student WHERE studentno in ' 
             + ' ( select studentno from score where ) ' + KM
             + ' between ' + CJD ;
      with query1 do
      begin
        close;
        sql.clear;
        sql.Add(sSql);
        open;
      end;
    end;
      

  9.   

    这是pdbird(老巢)的错误提示:
     在查询表达式错误'studentno in ( select studentno from score where )Math between 60 and 85'中
      

  10.   

    where )Math  把 )加到  + CJD +‘)‘