I have two tables in my database called CartItems and OrderItems. I
store all of a session's shopping cart items in the CartItems table
using the sessionID as the identifier (called cartID in my DB). After
an order is placed and is approved, I would like to copy all of the
items in the CartItems table for that given cartID to the OrderItems
table given a new orderID.
I will know the cartID and orderID ahead of time and would like to
send them both into a stored procedure and have the transfer take
place.
Example:
take this data...
CartItems (table)
--------------------------------------
cartID | itemID | quantity | price
--------------------------------------
12345 2 1 12.95
12345 7 2 17.95
and make it this data...
OrderItems (table)
--------------------------------------
orderID | itemID | quantity | price
--------------------------------------
00001 2 1 12.95
00001 7 2 17.95
via some stored procedure that I send (@cartID,@orderID)
Any help would be greatly appreciated!! 5 1949
Not tested but something like this:
create proc cartunload @cartid int
as
insert into orderitems select cartid as orderid, itemid, quantity, price
from cartitems where cartid = @cartid
delete from cartitems where cartid = @cartid
You might think about normalizing and if it fits your needs, look at
orders and order details tables in northwind.
HTH
Ray Higdon MCSE, MCDBA, CCNA
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks for your reply... this would work IF the cartID and orderID could
be the same value. In my case, however, they cannot. I need to send
both the cartID and my new orderID to the stored procedure and have it
take all of the data for a given cartID and put it in the OrderItems
table with the new orderID. I tried the following based on your example
to no avail:
CREATE PROCEDURE TransferCartItems
(
@cartID int,
@orderID int
)
AS
INSERT INTO OrderItems
@orderID, Select eventID, ticketType, ticketPrice, quantity
FROM CartItems
WHERE CartID = @CartID
GO
Any ideas? This fails with a syntax error.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Rick Clift (sp*******@yahoo.com) writes: Thanks for your reply... this would work IF the cartID and orderID could be the same value. In my case, however, they cannot. I need to send both the cartID and my new orderID to the stored procedure and have it take all of the data for a given cartID and put it in the OrderItems table with the new orderID. I tried the following based on your example to no avail:
CREATE PROCEDURE TransferCartItems ( @cartID int, @orderID int ) AS
INSERT INTO OrderItems @orderID, Select eventID, ticketType, ticketPrice, quantity FROM CartItems WHERE CartID = @CartID GO
Any ideas? This fails with a syntax error.
SELECT @orderID, eventID, ...
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
>> I have two tables in my database called CartItems and OrderItems. I
store all of a session's shopping cart items in the CartItems table
using the sessionID as the identifier (called cartID in my DB). After
an order is placed and is approved, I would like to copy all of the
items in the CartItems table for that given cartID to the OrderItems
table given a new orderID. <<
Have you considered that the things in the cart are just like the
things in order, but with a different LOGICAL status? Why not add
another column and not PHYSICALLY slide rows around as if they were
paper forms or punch cards?
1) There would be no way for the same item to be in both a cart and an
order, while your two-table scheme can be screwed up without really
elaborate constraints or triggers on the tables.
2) You can extend the status code to capture more information, such as
"returned to shelf from cart", or "returned to shelf from order"
3) Updating a status is faster than all that extra I/O, index
rebuilding, etc,
Yes that does the trick... thank you very much.
Rick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: gordy |
last post by:
edit: this came out longer than I thought, any comments about anything
here is greatly appreciated. thank you for reading
My system stores millions of records, each with fields like firstname,...
|
by: Edward Diener |
last post by:
Coming from the C++ world I can not understand the reason why copy
constructors are not used in the .NET framework. A copy constructor creates
an object from a copy of another object of the same...
|
by: Andromeda |
last post by:
I have two tables... one contains all the loan officer information
(name/address/phone/email/etc) the other is a NH license table which
lists has 3 columns - txtLOName, dtDateHireSent,...
|
by: Tlm |
last post by:
Hello All,
I have a form (FrmA) with a subform (SubFrmB) embedded in it. SubFrmB also
has a subform embedded in it (SubFrmC) The form's recordsource is based on a
table (TblA). SubFrmB's...
|
by: Hi5 |
last post by:
Hi,
I am new to access I usedto work in Oracle and Mysql.
I am after a way that enables me to populate a database I designed in
access with lots of data which can be sorted in excel sheets,
...
|
by: Wilfried |
last post by:
Hi,
I have 5 tables:
main
data1
|
by: Alfonso Morra |
last post by:
Hi,
I am writing a messaging library which will allow me to send a generic
message structure with custom "payloads".
In many cases, a message must store a non-linear data structure (i.e....
|
by: igendreau |
last post by:
I have a database with a Header table. Each record in tblHeader has
two One-to-Many Relationships: with tblLines and tblKeys. The HeaderID
field ties tblHeader to the other two tables. The data...
|
by: JMO |
last post by:
I can import a csv file with no problem. I can also add columns to the
datagrid upon import. I want to be able to start importing at the 3rd
row. This will pick up the headers necessary for the...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |