Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2004, 03:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie stored procedure questions

Question 1. See code below. First off I am new to stored procedures so this may be wishful thinking, but I would appreciate any help on this in understanding it better. What I am trying to do is Insert the item requested into one table and Select it's ID(this part works), then I want to Select the current stock form my Inventory table and return that value through the Response.Write .Parameters("@intOnOrderCount") or does this need to be a Recordset, I am only returning one value? What I don't understand is how to link more than one table up to a stored procedure, I have tried alot of stuff but ended up here.

Question 2. The ultimate thing I want to do is have the user request an item. Then the database will Insert this information. From there Select the requested items inventory and subtract it, if the inventory is below a certain count I want it to return a value so I can send a notification email to me. Is this even possible before I continue on?

'ASP CODE
    Set objCmd = Server.CreateObject("ADODB.Command")
        With objCmd
            .ActiveConnection = strConnect
            .CommandText = "sp_InsertItems"
            .CommandType = adCmdStoredProc
            .Parameters.Append .CreateParameter("@InPut_OrderID", adInteger, adParamInput, 4, NewOrderID)
            .Parameters.Append .CreateParameter("@InPut_OrderID", adInteger, adParamInput, 4, UserID)
            .Parameters.Append .CreateParameter("@InPut_Item_ID", adInteger, adParamInput, 4, ItemID)
            .Parameters.Append .CreateParameter("@InPut_QtyOrdered", adInteger, adParamInput, 4, QtyOrdered)

            .Parameters.Append .CreateParameter("@intItemOrderedID", adInteger, AdParamOutput, , 0)
            .Parameters.Append .CreateParameter("@intOnOrderCount", adInteger, AdParamOutput, , 0)

            .Execute

            'Selected @@Identity--This Works
            Response.Write .Parameters("@intItemOrderedID")

            'Inventory Count from another table, this doesn't work
            Response.Write .Parameters("@intOnOrderCount")

            End With

        Set objCmd = Nothing


'Stored Procedure
Create PROCEDURE sp_AddItemsToOrder
(
    @InPut_OrderID int,
    @InPut_UsrID int,
    @InPut_Item_ID int,
    @InPut_QtyOrdered int,
        @intItemOrderedID int OUTPUT,
        @intOnOrderCount int OUTPUT
)
AS
BEGIN
    INSERT INTO ItemsTable
        (
        Order_ID, Usr_ID, Item_ID, Qty
        )
    VALUES
        (
        @InPut_OrderID, @InPut_Usr_ID, @InPut_Item_ID, @InPut_QtyOrdered
        )
    Declare @ItemOrderedID int
    SELECT @ItemOrderedID = @@IDENTITY
    SET @intItemOrderedID = @ItemOrderedID

    'How do I get this to link up with @intOnOrderCount????
    SELECT OnOrder
    FROM Inventory
    WHERE Item_ID = @InPut_OrderID
END

GO

Thanks In Advance
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
 
Old October 19th, 2004, 03:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Mike,
Code:
'How do I get this to link up with @intOnOrderCount????
    SELECT @intOnOrderCount=OnOrder
    FROM Inventory
    WHERE Item_ID = @InPut_OrderID
    Hope this is what you are looking for. If not, explain what does @intOnOrderCount mean here, and how does that link with the data present in the Inventory table, may be with some sample data.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 19th, 2004, 04:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a million, that worked! One more question, Is this doable through a stored procedure?

Question 2. The ultimate thing I want to do is have the user request an item. Then the database will Insert this information. From there Select the requested items inventory and subtract it, if the inventory is below a certain count I want it to return a value so I can send a notification email to me. Is this even possible before I continue on?
 
Old October 19th, 2004, 04:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, you can do that. It is possible.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
few questions for newbie please pepperoni00 ASP.NET 2.0 Professional 5 January 8th, 2008 02:01 AM
JDK, newbie questions =D Ixidor Java Basics 5 March 12th, 2006 04:53 AM
Newbie Questions chimp Crystal Reports 0 November 7th, 2005 10:54 AM
CR10 newbie questions drunken Crystal Reports 0 January 19th, 2005 03:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.