Stored procedure problem

Discussion in 'ASP .Net' started by martinharvey via DotNetMonster.com, Nov 28, 2005.

  1. 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

    --
    Message posted via DotNetMonster.com
    http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200511/1
     
    martinharvey via DotNetMonster.com, Nov 28, 2005
    #1
    1. Advertising

  2. 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

    "martinharvey via DotNetMonster.com" <u14945@uwe> wrote in message
    news:5807489da7800@uwe...
    > 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
    >
    > --
    > Message posted via DotNetMonster.com
    > http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200511/1
     
    Eliyahu Goldin, Nov 28, 2005
    #2
    1. Advertising

  3. 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
     
    =?Utf-8?B?VmVua2F0X0tM?=, Nov 28, 2005
    #3
  4. Eliyahu Goldin wrote:
    >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

    --
    Message posted via DotNetMonster.com
    http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200511/1
     
    martinharvey via DotNetMonster.com, Nov 28, 2005
    #4
  5. Venkat_KL wrote:
    >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

    --
    Message posted via http://www.dotnetmonster.com
     
    martinharvey via DotNetMonster.com, Nov 28, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon Shaw

    Stored Procedure Problem

    Leon Shaw, Jul 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    378
    Jurjen de Groot
    Jul 29, 2003
  2. ElmoWatson

    Stored Procedure/Parameter problem

    ElmoWatson, Aug 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    502
    Jerry
    Aug 6, 2003
  3. Bilbo
    Replies:
    3
    Views:
    435
    Bilbo
    Nov 20, 2003
  4. The Clansman

    Stored Procedure problem

    The Clansman, May 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    358
    Julie
    May 19, 2004
  5. Mike P
    Replies:
    0
    Views:
    3,328
    Mike P
    Jun 19, 2006
Loading...

Share This Page