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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:11:26+00:00 2026-05-26T03:11:26+00:00

Assume that we have this SQL statement: UPDATE article SET saison=’12E’, mode=’ECH’, client=’SAS’, WHERE

  • 0

Assume that we have this SQL statement:

UPDATE article SET saison='12E', mode='ECH', client='SAS', WHERE ID='3448fe81-1bec-e011-8546-001f3ccf8f20'

This SQL statement is generated by concatenated strings like this:

// saison change
procedure TarticleEditForm.saisonComboChange(Sender: TObject);
begin
    SQLQuery := SQLQuery + 'saison=''' + saisonCombo.Text + ''',';
end;

// client change
procedure TarticleEditForm.clientComboChange(Sender: TObject);
begin
    SQLQuery := SQLQuery + 'client=''' + clientCombo.Text + ''',';
end;
.
.
.

As you see, there is a comma before “WHERE” clause. How can I remove the last comma to have the correct statement:

UPDATE article SET saison='12E', mode='ECH', client='SAS' WHERE ID='3448fe81-1bec-e011-8546-001f3ccf8f20'

RMQ: the number of comma is not fixe, it can be 1, 2, 5…

thank you.

The solution is replacing “, WHERE” by “WHERE”

 SQLQuery := StringReplace(SQLQuery , ', WHERE', 'WHERE', [rfReplaceAll]);

I am using this to trace every change in HISTORY Table.
Thank you all.

  • 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-26T03:11:27+00:00Added an answer on May 26, 2026 at 3:11 am

    Rather than concatenating the changes to the SQL string as they happen, store them in a collection and build you SQL string after all the options have been evaluated.

    Then you will know how many fields are going to be changed and build the statement correctly. Of course this will require you to store not only the value but also the name of the fild being changed:

    [pseudo code]

    for i=0 to fields_changed.count {
      sql = sql + fields_changed(i).field_name + " = " + fields_changed(i).new_value
      if i < fields_changed.count {
        sql = sql + ", "
      }
    }
    sql = sql + " WHERE ..."
    

    EDIT: The other option you have is to simply perform a string replace on , WHERE with WHERE just before executing the statement; since the word ‘where’ is a reserved word and should not occur more than once in your SQL statement. This may be the simpler solution even if it feels like a bit of a hack.

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

Sidebar

Related Questions

Assume that I have this piece of code: @interface Foo : NSObject { Bar
Assume I have a class that looks like this: class Sample { public string
Assume that you have a running SQL Server Express instance named (local)\SQLEXPRESS. Its database
I have a very complex Linq to SQL query that returns a result set
I have some code that currently builds up an In statement in SQL. I
Assume that we have N erlang nodes, running same application. I want to share
Assume that we have multiple arrays of integers. You can consider each array as
Assume that I have the ItemSource bound and i am getting the data. Now
Assume that we have the following code: class Program { static volatile bool flag1;
Let's assume that we have a vector like x = -1:0.05:1; ids = randperm(length(x));

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.