I want to write a Stored Procedure for these 2 tables ,
I have this SP but it doesn't achieve my point.. -
-
CREATE proc [dbo].[Sp_Insert]
-
@prdctName NVARCHAR(50),
-
@ordrdQnty INT,
-
@ordrPrice MONEY
-
--@TrnId INT
-
-
AS BEGIN TRAN
-
declare @TrnId int
-
-
set @TrnId = SCOPE_IDENTITY()
-
--IDENT_CURRENT
-
-
Insert into [OrderProduct]
-
(prdctName ,ordrdQnty ,ordrPrice,TrnId )
-
values (@prdctName,@ordrdQnty,@ordrPrice ,@TrnId)
-
-
-
declare @OrdrId int
-
declare @TrnTotal int
-
-
set @OrdrId=@@IDENTITY
-
--set @TrnTotal = @ordrPrice
-
--@ordrdQnty *
-
-
if @@ERROR<>0 goto ERR_
-
-
-
Insert into [Transaction] ( OrdrId,TrnDate )--,TrnTotal
-
-
values (@OrdrId,GETDATE() )--,@TrnTotal)
-
if @@ERROR<>0 goto ERR_
-
-
commit tran
-
return 0
-
-
ERR_:
-
rollback tran
-
return 1
-
-
GO
-
-
10 1534
External storage sites are blocked by our firewalls. Attach the image to the thread itself.
You said the SP doesn't achieve your point. But you haven't told us what the "point" is so there's nothing we can help you with.
Thank you for your reply, I have 2 tables one of them is OrderProduct (orderId P.K.,ProdctName,Quantity,Price)which store the list of items that the customer want one by one , the second table I named it Transaction(TrnId P.K.,orderId f.K.,Datetime) which it suppose to group the list of Orders by one TrnId, So the realtion between these 2 tables is one(TrnId)-to-many(Orders).
In my SP I just store the orders without specifying TrnId ,
Actully I want to program the selling form.
I don't know what do you mean about the image!
I hope to be my point is clear now , and I'm sorry for my first bad description..
You still haven't explained what problem you're having. You said you want to store the order without transaction. Which doesn't make sense because now you have no way of tying the order to the transaction. But aside from that, you still need to explain what problem you're having implementing that. Is it giving you an error? What's the error code? Is it not working the way you want? What is it doing instead? How should it work? What is some sample data and results?
My comment about the image is that you used a site to store the image. My firewall blocks that site, so I can't see the image. Attach the image to the forum thread.
My SP store the orders in Transaction without specify the TrnId, there is no error, but I need to link orders with TrnId when It saved in Transaction table..
OrderedProduct
|Price|Quantity|ProductName|OrderId|
|10 | 2 | A | 1 |
| 80 | 1 | C | 2 |
| 30 | 5 | B | 3 |
| 60 | 3 | B | 4 |
========================================
Transaction
| Date | TrnNo |OrderId|
| 12:10/05-11-14 | 1 | 1 |
| 12:11/05-11-14 | 1 | 2 |
| 12:16/05-11-14 | 2 | 3 |
| 12:17/05-11-14 | 2 | 4 |
Is your question that you don't know how to get the OrderID that you just inserted?
my question is what is the required editing that SP need to store the Orders in Transaction table with one TrnId to let me then write query to calculate the total amount of the list of orders as group of TrnId.
Suppose there is customer who buy (1-a,2-b,3-c) as names of products ) these products should store to OrderProduct Table with the quantity and Price for each one products so I have 3 fields in OrderProduct then these Orders supposed to be stored in Transaction Table so I need to join these 3 orders with one TrnId as it one operation that happen at the same deal and for one customer ..
I hope I could making my idea clearer ..
If you only want one transaction record but link it to multiple order records, you need to store a transaction id in the order table. Not the other way around like you have now because that's impossible.
How I will get Transaction Id value If I stored it in the Order table, the Order table is filled with data at first ..
Insert the transaction first
Sign in to post your reply or Sign up for a free account.
Similar topics
by: shiyuan |
last post by:
Dear Sir:
We have created a table with a column of composite type.
how can we insert values in this table.
for exemple:
create table aa (a int);
create tabel bb (b aa);
how to insert data ...
|
by: Hi5 |
last post by:
Hi,
Any Idea how, I can make an Insert statement to insert data into 6
different tables, that are all holding all data of my database?
Is there any example?
I would be grateful if you could...
|
by: Pratik Gupte |
last post by:
I have created a database in .mdf format, but I am unable to insert data
into its tables. Can anybody help how to insert data using ASP.Net 2.0 using
SQL Server 2005 Express edition in windows...
|
by: tezza98 |
last post by:
Hi im creating a function to insert data from a MYOB file into an Access database. what im trying to do is copy entire tables from MYOB into ACCESS.
Im using a simple Access Database with so there...
|
by: hooliovelasko |
last post by:
Sorry for my English. I use C#. I have two tables with relation(category an product) i want to load them in treeview. I load category table - parent nodes but i want to load and product table - child...
|
by: msmjsuarez |
last post by:
Hello,
I need help...
How to automatically insert data to mysql database without submit button using php?
Is there a way on this?
thanks a lot.
|
by: msmjsuarez |
last post by:
Hello.
Is it possible to insert data to two tables at one time using one form only?
I'm using php and mysql.
Thanks advance.
|
by: shivasusan |
last post by:
Hi!
I have two tables in my database (userinfo, logininfo)
- userinfo table has five fields (uname, pws, con_pws, squest, sans)
- logininfo table has then six fields (fname,lname,dob,add1,...
|
by: southpawjoe |
last post by:
Hi,
I would like to insert data into two related tables in a SQL Server 2008 database. I created the following stored procedure but it has a problem. When I add a record, the State table gets...
|
by: Bappa Dey |
last post by:
Hi..
// i have a database in mysql, which has 14 tabels, among them i can put/insert data into 12 tables successfully using php, but 2 tables are not taking any data.//
<from></from> is ok
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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...
| |