Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:37:22+00:00 2026-06-15T02:37:22+00:00

I’m trying to convert some of the SQL code we use in our projects

  • 0

I’m trying to convert some of the SQL code we use in our projects towards using parameters. Inserting works fine:

with SQLDataSet do begin
  Close;
  SQL.Text := 'INSERT INTO testtable (keyname, waarde) VALUES (:keyname,:waarde)';
  Prepare;
  for i := 1 to 10000 do begin
    ParamByName('waarde').AsInteger := i;
    ParamByName('keyname').AsString := 'Testa'+IntToStr(i);
    ExecSql;
  end;
end;

work fine and fast.

But, I can’t get it to work with select Statements.
At first the following seems to work:

with SQLDataSet do begin
  SQL.Clear;
  SQL.Text := 'SELECT :waarde = waarde FROM testtable WHERE keyname = :keyname';
  Prepare;
  for i := 1 to 10000 do begin
    ParamByName('keyname').AsString := 'Testa'+IntToStr(i);
    ExecSQL;
    k[i] := ParamByName('waarde').AsInteger;
    Close;
  end;
end;

but the value of k[i] just gets filled with 0’s. Do I need to keep selecting the old fashioned way, issuing the query, opening and traversing the result set or is there a way when you have a query with only 1 row to select right into a parameter value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:37:23+00:00Added an answer on June 15, 2026 at 2:37 am

    Short answer: Keep doing it the way you do now. There is no reason to use parameters to fetch query results.

    Longer answer:

    You can use an ADOCommand (not sure what the ODBCExpess equivalent is) and execute a SELECT INTO query:

    SELECT
      YourField
    INTO
      :YourParam
    FROM
      YourTable
    WHERE
      ID = 1
    

    In a similar way you can execute stored procedures.

    However, using parameters is mainly done for making sure the input is valid and is treated as a certain type. It also allows databases to use better caching, because they cache the query once and see the parameters as a variable piece.

    For the output (returned fields), this is useless. The query is already cached even with normal columns. So just execute the query and read its fields as you do now. You can use parameters, but they only add more complexity and limits, without any benefits. These kinds of parameters are specifically useful for reading output of stored procedures and program blocks.

    In your specific case, you want to retrieve a lot of fields (maybe all?) In that case it may be better to execute a single query and loop through the results, than to execute 1000 little queries like you do now. Each query has a little overhead for initialization and such, and you save that overhead a 1000 times if you manage to query all the data you need at once.
    Also, if you do that (fetching multiple records of data), there is no way to fetch those results into parameters, so that’s one of the reasons why parameters would limit you and thus another reason to use parameters only for input if you can.

    Your results:

    The reason you’re getting 0 is because you never set the parameter value. So its value remains NULL. Because you request the value using AsInteger, this value is converted to an integer, therefore returning 0.

    The value returned by the query (the one field that is returned) is probably 0 as well. You actually query an expression X = Y where X is the value of the parameter and Y is the value of the field. Since the parameter’s value is NULL, the expression always evaluates to false (using the normal comparison operators on NULL values always returns false, no matter which operator you use or what the other value is). Since true and false are usually represented as 0/1 tiny int fields, the field value would probably return 0 as well. But you don’t use this value in your posted code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Let's say I'm outputting a post title and in our database, it's Hello Y’all
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.