#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    1
    Rep Power
    0

    Question Need help with parameters in SQL Query


    Hello!

    I'm having troubles with a parameter in my SQL Query:

    Code:
    Select * 
    from A_REGISTER 
    where :fältparameter LIKE :sökparameter
    (fält= field, sök = search)

    The searchparameter works, but the fieldparameter doesnt. I assign the values and execute the search this way:

    Code:
    procedure TForm2.Button1Click(Sender: TObject);
    begin
    if RadioButton1.Checked=true then
          query1.ParamByName('fältparameter').AsString := 'Namn';
    
      if RadioButton2.Checked=true then
          query1.ParamByName('fältparameter').AsString := 'Kemnamn';
    
      with Query1 do begin
        Close;
        query1.ParamByName('sökparameter').AsString := '%'+edit1.text+'%';
        ExecSQL;
        Open;
      end;
    end;
    The weird thing is that if i put an "a" in the edit1box the query returns all the posts in the database.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    14
    Rep Power
    0
    don't pass the table name as parameter, pass only values.

    if RadioButton1.Checked= then
    csSQL := 'Select * from A_REGISTER where Field1 LIKE :sökparameter

    if RadioButton2.Checked then
    csSQL := 'Select * from A_REGISTER where Field2 LIKE :sökparameter
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    3
    Rep Power
    0
    you can't use variant for TableName,fieldName, ViewName, etc.

IMN logo majestic logo threadwatch logo seochat tools logo