I have a database in which I store product sales. My sales table is made up of the following fields: [saleID], [itemCode], [Date], [storeID], [quantitySold]. The problem is I want the user to be able to insert a payment for multiple saleIDs.
Prices come from the items table but there may be a discount if multiple items are purchased. I want to be able to store a finalPayment field and multiple sales connected to it, then group the sales by the specific finalPayment. However there could be same sum finalPayments that do not belong to the same sales batch so I cannot group by finalPayment as a field in the sales table.
I could create a finalPayments table and every time a multiple item sale and discount is made, store a new final payment in it, retrieve the last finalPaymentID and then store it in the sales table (in a new field [finalPaymentID] that I will create) for every sale that belongs to it. Then i could group sales by finalPaymentID.
Could the last finalPaymentID in the table be created by some other store? Can there be a concurrency problem? Do I need to lock the table in some way until the finalPaymentID is retrieved and stored in the sales table? How would you implement this?
I would create multiple tables.
Table Order would contain OrderId, Date, StoreId
Then I would create an OrderItem Table which would contain OrderId, Item, Qty, Price
There would be a one-to-many relationwhip from the orderItem table to the Order table.
That way you can group by OrderId to get your quantities and values.
Sounds like a cart schema - something like this should do:
Product (your Items table)
- | ProductId | Whatever
Payment
- | PaymentId | Date | Whatever
Cart
- | CartId | UserId | ProductId | PaymentId
For each product, you have a record in Product. Each 'Payment' record is a sum of all the products (the cart total). Each record in sale is a unique identifier to each item in the 'cart', so that you can say UserID 1 has 3 items in his cart for a specific payment Id (3 records).
I actually did with the payments table. I used
string insertSQL = "INSERT INTO [payments ] ([paymentSum]) VALUES (#paymentSum);SELECT ##Identity";
and then stored the paymentID retrieved into the sales table for each sale that is part of the batch.
Related
I have two tables, shops and products. Table shop with columns shopId (PK) and shopName. Another table Products has columns productId (PK) and productName. Because I have a relationship many-many between two tables I create another table shopProduct with two columns shopId and productId.
For example I have shop1 with id=1 and I have shop2 with id=2, product1 with id=1 and product2 with id=2. and the records of the table shopProduct is 1-1 ,2-2.
But now I want to have a product3 with id=3 that apply to all shops.
I consider in the real problem that i have about 250 shops.
How can implement this without a stored procedure?
I don't want to do of course 250
insert into shopProduct (shopId, productId)
values (#shopId,#productId).
Can I do for loop for example to feed the the shopId value every time?The other value for product id is the same every time.
From my understanding of this question, try this... Seems too simple, but...
Insert into ShipProduct (ProductID, ShopID)
Select 3, ShopID
From Shops
Im making an ordering system where there is a product,supplier and order table. What I'm trying to do is when you order, it can have multiple product and one supplier. Example us OrderID 001 it can have 3 products from product table and 1 supplier from supplier table. How can I do this?
Sorry for asking too much but I don't have a code yet for this part of the system as I don't know where to begin. Thank you.
Create an Orders Table.
Add all ordered products to the order Table.
In the table the three products would all have the same order_id, but a different or (in case someone bought two of the same) same product. You will also need to track the amount they purchase with each row, in case the amount changes.
Select Sum(purchase_amount) from orders where order_id = "YOUR_ORDER_ID"
Select * from orders where order_id = "YOUR_ORDER_ID"
...3 rows show up
You may want to have an order_summary table as well that contains the total amount, etc.
ProductName price brand Quantity Net AmountNet Amount Update
I have the above table in which I have to insert the products which users have added to their cart.
Users can add multiple products to their cart.
I have that table of user added products in the session and I am reading it row by row by taking that session table as a datatable.
I have to insert all products row by row in above table.
I also have another table as follows:
orderID CartItemID RegistrationID OrderDate NetAmount Remarks Created
My question is, how to give one unique order id to all products ordered by a user?
In my project I use 3 tables, to solve this problem
CREATE TABLE cart(
ID NUMBER,
CUSTOMER_ID NUMBER,
DATE DATE DEFAULT SYSDATE,
SESSION_ID VARCHAR2(32 BYTE)
)
CREATE TABLE cart_parameter(
SESSION_ID VARCHAR2(32 BYTE),
CODE VARCHAR2(32 BYTE),
TYPE VARCHAR2(32 BYTE),
AMOUNT NUMBER
)
CREATE TABLE product(
ID NUMBER,
CODE VARCHAR2(32 BYTE),
description VARCHAR2(200 BYTE),
price NUMBER(30,2),
... more info
)
Other tables
This architecture is correct so that the basket can be a different number of items, and in different tables. for example you have a table with computers, smart phones, books, and so on. At your option you put the product ID, but different tables can be different products with the same identifier. Then you have a problem with the expansion of applications
This function returns a unique value for this session
FUNCTION getSessionID
IS
BEGIN
RETURN utl_raw.cast_to_raw(DBMS_OBFUSCATION_TOOLKIT.MD5(TO_CHAR(customer_id) || TO_CHAR(systimestamp, 'DDMONYYYYHH24MISSFF') || s_user_ip || dbms_random.random()));
END;
Use this sessionID for connect the cart table and cart_parameter table
P/S: Forgive me for my English, it's all google translate
I have table called customers contain custID,custName, another table called products contain proID,proName,price and third table Cust_PRo contain id,custID,proID.
i filled the products with data like this:
proID proName price
1 potato 100
2 cotton 600
3 rice 200
and in another form i have combobox i filled it with products names and textbox to write the customer name and gridview to appear data and there are two buttons one to add the values into grid and second to save it into database.
when i write the customer name and choose the products the data appear in the grid like this:
custName ProName
john potato
john cotton
john rice
as you see one customer can take many products the problem is to add the values into database i want when the user click the save button the data insert into the database like this:
first customers table:
custID custName
1 john
second Cust_PRo table:
id custID ProID
1 1 1
2 1 2
3 1 3
thank you
i'm not sure i got you 100% but i think you need some algorithm or something.. anyway
first, you need to generate a CustID for your new customer, to do that you need to get the maximum CustID from the table Customers and add it to 1 to avoid Primary key violation.
select max(CustID) from Customers
then, you'll be good to go. You have (CustID and ProdID from comboBox1.SelectedValue;)
I added the values to datatable and then used the SqlBulkCopy class to insert these values into database
I have some data within a table I am importing into an ERP solution. The data is presented like this:
buyer name,order id,shipment item id,sku,quantity shipped, price etc
The shipment item ID is a unique value and is the primary key along with the order id.
My problem is this:
I need to locate each distinct order and create a sales order based upon that information.
The issue I am having is:
Each shipment item ID has its own row within the database and a simple
while(reader.read()){
...logic here...
}
will not work as it will attempt to create n amount of sales orders for the same customer.
I need to formate a query that will take each shipment item ID and put its SKU, quantity etc into one row so I can attach it properly but I am unsure how this would work.
Any help would be much appreciated.
You need to use a group by clause to deduplicate the rows to get the top level information
SELECT [buyer name], [order id], etc
FROM orderTable
GROUP BY [buyer name], [order id], etc
WHERE [order id] = 1
then select all the rows seperately
SELECT *
FROM orderTable
WHERE [order id] = 1
I have found a solution with the ERP software provider which will allow me to use a basic SQL statement and do an update on the any sales order which has a primary key of the order ID. This will allow each corresponding shipment item id to be added to the sales order without having to do extra SQL "massaging" as if the record exists it will update it, otherwise it will create a new one.
Thanks everyone for your suggestions.