Question about global variables

  • Hi all,

    Could someone explain the code (in red) below for me??  In particular, what reasons might there be for the use of global variables in the values list?

    My understanding is that this code creates a stored procedure, which will then be used for insertions into the SalesCopyInsert. If that's correct, why are the values prefaced by variables??  I don't understand TSQL that well, so this is possibly an obvious one for some of you.

    Thanks,

    Jaybee.

    create proc SalesCopyInsert

    @SalesOrderID int,

    @SalesOrderDetailID int,

    @CarrierTrackingNumber nvarchar(25),

    @OrderQty smallint,

    @ProductID int,

    @SpecialOfferID int,

    @UnitPrice money,

    @UnitPriceDiscount money,

    @LineTotal money,

    @ModifiedDate datetime

    as

    insert into SalesCopy (SalesOrderID, SalesOrderDetailID,

    CarrierTrackingNumber, OrderQty, ProductID,

    SpecialOfferID, UnitPrice, UnitPriceDiscount,

    LineTotal, ModifiedDate)

    values (@SalesOrderID, @SalesOrderDetailID,

    @CarrierTrackingNumber, @OrderQty, @ProductID,

    @SpecialOfferID, @UnitPrice, @UnitPriceDiscount,

    @LineTotal, @ModifiedDate)

     

  • Jay,

    Yes, the code creates a stored procedure that will insert a record into the SalesCopy table.  The stored procedure requires that you pass 10 values to the procedure represented by the variables, and these are used in the insert statement to update the table with a new record.

    You may want to take a little time and read BOL for more info on stored procedures and the insert statement.

     

  • Sorry, I've worked it out - I was forgetting that this was a code to create the SP to optimise future insertions - not immediately execute one.

    My bad, Lynne thanks for your help.

     

    Jaybee.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply