SQLite question

+1 louis foster · January 12, 2015
Bucky,
I love what you do for all of us, Thank You.

I am working on a android app, I have a database that has a case_qty column a case_cost column and a cost column, can sql do
case_cost / case_qty and put the answer in cost when the record is being added?

Thanks,
Louis

Post a Reply

Replies

Oldest  Newest  Rating
+1 Hector Boone · January 12, 2015
You should be able to do

update your_table set cost = (case_cost / case_qty) where your_where_clause
+1 Branislav Lazic · January 12, 2015
Yes, all you need is a appropriate query:

Like: 


SELECT case_qty, case_cost, case_cost / case_qty as cost_per_qty FROM table;
0 louis foster · January 13, 2015
Thank you both for your input, all this is new to me,
I guess I would need to do a function that gets the information
and then call that function in the update statement?

Thank you,
Louis
+1 Branislav Lazic · January 13, 2015
No! Do not commit update! Just programmatically calculate cost in your Android app and commit insert! Or something like: 


INSERT INTO cases (case_cost, case_qty, cost) VALUES (10.2, 5, 10.2 * 5);
  • 1

Java / Android Development

107,234 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator