Move table information via button

Discuss the database features
Post Reply
KLeabu46
Posts: 22
Joined: Tue Jun 10, 2014 11:02 pm

Move table information via button

Post by KLeabu46 »

Hello,
I am working on a database for management of a retail store. I sell expensive sewing machines that each have unique serial numbers. I already have tables linked with one to many relationships and no data is duplicated. What I want to do is create a button that essentially moves a machine from my inventory table to my sold table (ie. Deletes the serial number from my inventory and saves it to my sold table) is there any way for me to do this?

Thanks,
Kleabu46
OpenOffice 4.1.0 running HSQLDB in server mode on Windows 10
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Move table information via button

Post by MTP »

Sure, if you learn how to program macros that execute SQL code. It's a bit of a steep learning curve for the benefit, though.

Why not instead have a column in your inventory table named "Sold" that stores the sell date? Then to check your current inventory you run the query

Code: Select all

SELECT * FROM "Inventory" WHERE "Sold" IS NULL
And to see what you have sold

Code: Select all

SELECT * FROM "Inventory" WHERE "Sold" IS NOT NULL
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
KLeabu46
Posts: 22
Joined: Tue Jun 10, 2014 11:02 pm

Re: Move table information via button

Post by KLeabu46 »

I was initially thinking of doing it this way because I am linking my customer table with the sold table, that way when I look up my customer I can see what machine I sold them and when. When I sell a machine to someone, I want to be able to locate a machine in my inventory, sell it to the customer (link it to them) and have it not show up when I go to sell a different one to someone else. Can you suggest a smooth way to do this?
OpenOffice 4.1.0 running HSQLDB in server mode on Windows 10
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Move table information via button

Post by MTP »

You can have both "SoldDate" and "SoldTo" columns in the inventory table. To look up all machines sold to a particular customer by CustomerID:

Code: Select all

SELECT * FROM "Inventory" WHERE "SoldTo" = 5
or by CustomerName:

Code: Select all

SELECT * FROM "Inventory" 
   INNER JOIN "Customers" ON "Inventory"."SoldTo" = "Customers"."CustomerID"
   WHERE "Customers"."CustomerName" = "A"
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
Post Reply