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 doingCode:adoquery1.SQL.Clear; adoquery1.SQL.Add('Update Stock'); adoquery1.SQL.Add('Set StockLeft = '+ (adotable2['StockLeft']-1)); adoquery1.SQL.Add('Where PLUNumber = 15'); adoquery1.execsql;
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
Code:adoquery1.SQL.Clear; adoquery1.SQL.Add('Update Stock'); adoquery1.SQL.Add('Set StockLeft = StockLeft-1'); adoquery1.SQL.Add('Where PLUNumber = 15'); adoquery1.execsql;
Omg Lol, thank you >__>
What you were doing was adding an integer to a string.
It would'a worked if you'da did
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.Code:adoquery1.SQL.Add('Set StockLeft = '+ IntToStr(adotable2['StockLeft']-1));
But now you know how to append numbers to strings.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks