EXEC AND select statement

  • I need help with using the exec command and the select statement.

    I need to pull the data from a table using a select statement and use that data to supply a exec statement

    EXEC [dbo].[uspOrderDetail_Insert]

    SELECT @OrderID,utbCart.ProductID,utbCart.ReferenceName,utbCart.Quantity,

    utbCart.UnitCost,utbCart.ExtendedCost

    FROM utbCart WHERE

    utbCart.CartID = @CartID

    OR

    utbCart.ShopperID = @ShopperID

    Is it possible to do this?

    Dam again!

  • Like this:

    Declare @sql NVarchar(MAX);

    Set @sql = '';

    SELECT @sql = @sql + '

    EXEC [dbo].[uspOrderDetail_Insert] '+@OrderID+','+utbCart.ProductID

    +','''+utbCart.ReferenceName+''','+utbCart.Quantity

    +','+utbCart.UnitCost+','+utbCart.ExtendedCost+''''

    FROM utbCart WHERE

    utbCart.CartID = @CartID

    OR

    utbCart.ShopperID = @ShopperID

    Print @sql

    Exec(@sql)

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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