Stored procedure problem

  • Thread starter martinharvey via DotNetMonster.com
  • Start date
M

martinharvey via DotNetMonster.com

This is probably a very simple question but i am having problems with a
stored procedure syntax.

I want to insert into a Datatable ("Orders") "Name" and "Address" from a
datatable called "customer"
with the parameters customerId = @CustomerId

I also want to insert into the same Datatable ("orders") at the same time
"Name" and "Cost"
from a datatable called "products". The input parameter for this is cartID =
@cartId

I have tried this but it doesnt seem to work. Can anyone tell me where i am
going wrong.

CREATE PROCEDURE SP_CreateOrder
(@CustomerID Varchar (50), @CartID Char (36))

AS

INSERT INTO Orders (Name, Address, Name, Cost)

SELECT customer.Name, customer.Address, products.Name, products.Cost

FROM Customer AND Products Join ShoppingCart ON Products.ProductID =
ShoppingCart.ProductID

WHERE ShoppingCart.CartID = @CartID AND customerId = @CustomerId
 
E

Eliyahu Goldin

Your FROM clause in invalid. Look up T-SQL syntax for joins in any resource
available to you. It is hard to give a more precise advise without knowing
your tables structure and what exactly you want to achieve.

Eliyahu
 
G

Guest

Dear martinharvey,

(via:DotNetMonster.com)

There is no AND if you are working on two tables, it is only ( , ) comma;
With Comma, It works fine:

CREATE PROCEDURE SP_CreateOrder
(@CustomerID Varchar (50), @CartID Char (36))
AS
INSERT INTO Orders (Name,Address,ProductName,Cost)
SELECT customer.Name, customer.Address, products.ProductName,products.Cost
FROM Customer , Products Join ShoppingCart ON Products.ProductID =
ShoppingCart.ProductID WHERE ShoppingCart.CartID = @CartID AND customerId =
@CustomerId

Bye
Venkat_KL
 
M

martinharvey via DotNetMonster.com

Eliyahu said:
Your FROM clause in invalid. Look up T-SQL syntax for joins in any resource
available to you. It is hard to give a more precise advise without knowing
your tables structure and what exactly you want to achieve.

Eliyahu
This is probably a very simple question but i am having problems with a
stored procedure syntax.
[quoted text clipped - 26 lines]
WHERE ShoppingCart.CartID = @CartID AND customerId = @CustomerId

many thanks for your help again Eliyahu
mart
 
M

martinharvey via DotNetMonster.com

Venkat_KL said:
Dear martinharvey,

(via:DotNetMonster.com)

There is no AND if you are working on two tables, it is only ( , ) comma;
With Comma, It works fine:

CREATE PROCEDURE SP_CreateOrder
(@CustomerID Varchar (50), @CartID Char (36))
AS
INSERT INTO Orders (Name,Address,ProductName,Cost)
SELECT customer.Name, customer.Address, products.ProductName,products.Cost
FROM Customer , Products Join ShoppingCart ON Products.ProductID =
ShoppingCart.ProductID WHERE ShoppingCart.CartID = @CartID AND customerId =
@CustomerId

Bye
Venkat_KL

This was very helpful I will give it a try

many thanks

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top