Announcement

Collapse
No announcement yet.

SQL Abfrage mit OR geht nicht

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL Abfrage mit OR geht nicht

    hallo,

    weiss jemand warum bei der abfrage mit OR immer nur das feld CDLabel1 abgefragt wird? was in den restlichen feldern (CDLabel2 bis 5) steht wird nicht beachtet.
    mit der sql abfrage wird auf eine access datei zugegriffen.

    <PRE>
    SQL.Add(' WHERE (((CDLabel1) LIKE :X)) ');
    SQL.Add(' OR (((CDLabel2) LIKE :X)) ');
    SQL.Add(' OR (((CDLabel3) LIKE :X)) ');
    SQL.Add(' OR (((CDLabel4) LIKE :X)) ');
    SQL.Add(' OR (((CDLabel5) LIKE :X)) ');

    Parameters.ParamByName('X').Value := '%'+VarLAB+'%';
    </PRE>

    gruss matthias

  • #2
    Hallo, Ich denke der Fehler liegt darin, dass der Parameter nicht richtig verarbeitet wird.<BR>
    Versuche es mal so:<br>
    Parameters[0].asString := '%' + VarLab + '%';<br>
    Parameters[1].asString := '%' + VarLab + '%';<br>
    solange bis alle Parameters gefüllt sind.<br>
    bis von Parameters[0] bis Parameters[4]<br>

    habe ja keine grosse Ahnung von Access, aber<br> bei eine OR Abfrage geht eigentlich so:<br>
    Where (Feld1=? OR Feld2=? OR Feld3=? ...)<br>

    Gruss<br>
    Matthias<br&gt

    Comment


    • #3
      hallo matthias,

      danke für die antwort. habe es so versucht. hat aber nicht funktioniert.
      da ich auch keine grosse ahnung von access habe, erstelle ich die sql abfragen automatisch mit access. diese kopiere ich dann nach delphi und arbeite sie in den quelltext mit ein.

      die abfrage mit dem LIKE funktioniert aber:

      <PRE>
      SQL.Add(' WHERE CDLabel1 LIKE :X ');
      Parameters.ParamByName('X').Value := '%'+VarLab+'%';
      </PRE>

      zeigt dann alle datensätze in der der inhalt von VarLab plus andere zeichen enthalten ist.

      gruss matthias
      &#10

      Comment


      • #4
        Hi<br>setzte das "or" mal in die Zeile obendrüber.<br>
        <PRE>
        SQL.Add(' WHERE (CDLabel1 LIKE :X) or ');
        SQL.Add(' (CDLabel2 LIKE :X) or ');
        SQL.Add(' (CDLabel3 LIKE :X) or ');
        SQL.Add(' (CDLabel4 LIKE :X) or ');
        SQL.Add(' (CDLabel5 LIKE :X) ');
        Parameters.ParamByName('X').Value := '%'+VarLAB+'%';
        </PRE><br>cu Michae

        Comment


        • #5
          hallo matthias und michael,

          jetzt geht es :-) die lösung sieht so aus:

          <PRE>
          SQL.Add(' WHERE (((CDLabel1) LIKE :V)) ');
          SQL.Add(' OR (((CDLabel2) LIKE :W)) ');
          SQL.Add(' OR (((CDLabel3) LIKE :X)) ');
          SQL.Add(' OR (((CDLabel4) LIKE :Y)) ');
          SQL.Add(' OR (((CDLabel5) LIKE :Z)) ');
          </PRE>
          <PRE>
          Parameters.ParamByName('V').Value := '%'+VarLAB+'%';
          Parameters.ParamByName('W').Value := '%'+VarLAB+'%';
          Parameters.ParamByName('X').Value := '%'+VarLAB+'%';
          Parameters.ParamByName('Y').Value := '%'+VarLAB+'%';
          Parameters.ParamByName('Z').Value := '%'+VarLAB+'%';
          </PRE>

          also so wie matthias gesagt hat. der parameter muss immer einen anderen "buchstaben" haben.

          nochmal danke und gruss
          matthia

          Comment

          Working...
          X