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 7440225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:49:08+00:00 2026-05-29T10:49:08+00:00

I am using the Advantage Database Server from Sybase and have for the moment

  • 0

I am using the Advantage Database Server from Sybase and have for the moment a nice fast left join query, that runs really fast. The problem is that after running the query I would like to put the results into a string. I retrieved a dataset of 55000 entries.
Now It takes up to 16 sec. to put it into the string. My query only took 8 ms to run. My first atempt was this:

    aADSQuery.Open
    aADSQuery.First
    WHILE not aADSQuery.eof do
    begin
       s := s + aADSQuery.FieldbyName('Name').asString+',';
       aADSQuery.Next;
    end;

After, I tried this to avoid the aADSQuery.next, but the aADSQuery.RecordCount took
me 9 sec.

    aADSQuery.Open
    aADSQuery.First
    Count := aADSQuery.RecordCount;
    for i:=0 to count-1 do
    begin
      aADSQuery.RecNo := i;
      aADSQuery.FieldbyName('Name').AsString; 
    end;

The database is indexed, with primary key for the Entry ID and indizes for the other columns.
I thought about creating a view to count my entries to avoid the recordcount, that might exactly do the same than the sql count. But the count of the entries from the view took the same time as before. If I use the sql
count on my base table with 130000 entries it takes only 200 ms. But if I am doing a count on my resulting table, without using a view it takes me 9 s. I quess it is, because there are no indizes for the new temporary result table. Does anyone know how to handle this kind of problem in a proper way or how to get a faster result count?

Thank you very much

  • 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-05-29T10:49:09+00:00Added an answer on May 29, 2026 at 10:49 am

    Use some buffer based class such as TStringStream to populate the string. this will avoid slow reallocation of String concatenation (s := s + foo).

    Don’t use aADSQuery.FieldbyName('Name').AsString in the loop. It’s slow.
    Instead create a local variable F like this:

    var
      F: TField;
    
    F := aADSQuery.FieldbyName('Name');
    for i:=0 to count-1 do
    begin
      aADSQuery.RecNo := i;
      F.AsString; 
    end;
    

    I believe using aADSQuery.Next is faster than using RecNo

    procedure Test;
    var
      F: TField;
      Buf: TStringStream;
      S: string;
    begin
      aADSQuery.DisableControls;
      try
        aADSQuery.Open;
        F := aADSQuery.FieldbyName('Name');
        Buf := TStringStream.Create('');
        try
          while not aADSQuery.Eof do
          begin
            Buf.WriteString(F.AsString + ',');
            aADSQuery.Next;
          end;
          S := Buf.DataString;
        finally
          Buf.Free;
        end;
      finally
        aADSQuery.EnableControls;
      end;
    end;
    

    You can generate that string on the server side and return it to the client side without the need to construct any strings on the client side:

    DECLARE @Names NVARCHAR(max)
    SELECT @Names = ''
    SELECT @Names = @Names + ',' + ISNULL([Name], '') FROM MyTable
    SELECT @Names
    

    Also you could optimize performance by setting TAdsQuery.AdsTableOptions. Make sure AdsFilterOptions is set to IGNORE_WHEN_COUNTING and AdsFreshRecordCount is set to False.

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

Sidebar

Related Questions

I am working at the moment with the advantage database server from sybase. I
(Advantage Database Server) I have a table of service providers that, for auditing purposes,
Unfortunately we are using the Advantage Database Server Torture Edition Version 8.1. After I
So I am currently working on a migration from an old Advantage database server
We are using Delphi 7 to develop database apps with advantage as a backend.
Is it safe to update DBF files using Advantage Local Server .Net provider whilst
What's the advantage of using mock objects in comparison to a static test database
I am creating a new database for a web site using SQL Server 2005
Is there any advantage to using a NoSQL database of some sort as opposed
I inherited a project from a colleague that left the company. While examining his

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.