Closed Thread
Results 1 to 4 of 4

Thread: ADotable Trivial Question

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    ADotable Trivial Question

    Code:
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add('Update Stock');
    adoquery1.SQL.Add('Set StockLeft = '+ (adotable2['StockLeft']-1));
    adoquery1.SQL.Add('Where PLUNumber = 15');
    adoquery1.execsql;
    I have a table of stocks. I want it so that every time I execute this code, it decreases the stock with PLUNumber 15 by 1. So I tried doing

    adotable2['StockLeft']-1

    in the hope that it will read the 'Stockleft' WHERE the PLUnumber is 15 (and not the Sotckleft of the other stocks) and then decrease it. But It is not working.

    I could create a procedure before this to work out the value of the StockLeft first, but this is just long.

    Any solutions

    Thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: ADotable Trivial Question

    Code:
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add('Update Stock');
    adoquery1.SQL.Add('Set StockLeft = StockLeft-1');
    adoquery1.SQL.Add('Where PLUNumber = 15');
    adoquery1.execsql;
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: ADotable Trivial Question

    Omg Lol, thank you >__>

  5. #4
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: ADotable Trivial Question

    What you were doing was adding an integer to a string.
    It would'a worked if you'da did
    Code:
    adoquery1.SQL.Add('Set StockLeft = '+ IntToStr(adotable2['StockLeft']-1));
    But this is not as good, because what's up above there is pure SQL, which means the DB server/system does the read/decrement/write without any help from the program. Plus it takes shorter, which is better for your DB integrity and such.
    But now you know how to append numbers to strings.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question:technical question answering system algorithm?
    By vbehzadan in forum General Programming
    Replies: 1
    Last Post: 04-28-2010, 12:41 PM
  2. Replies: 0
    Last Post: 03-29-2010, 03:29 PM
  3. Replies: 4
    Last Post: 03-27-2010, 08:27 PM
  4. How do you validate an ADOtable?
    By 2710 in forum Pascal and Delphi
    Replies: 30
    Last Post: 03-17-2010, 10:01 PM
  5. QUESTION Strcat/Strstr/strcpy Question
    By wgre0111 in forum C and C++
    Replies: 1
    Last Post: 10-19-2008, 03:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts