Using Output Parameters

So far, you have used parameters to send data to the procedure. Now you will learn to return data from the procedure using an output parameter. We'll write a procedure, prGetCustomerCart, to return the Order ID for a shopping cart if one exists, or create a shopping cart if one doesn't exist. Then we'll call the prGetCustomerCart from inside the prAddItemToCart procedure and use an output parameter to pass the value back to the calling procedure.

Let's be clear on the logic for prGetCustomerCart. You pass it as a Customer ID and it returns an Order ID. To find the Order ID, it finds an open order for the customer (if one exists), or it creates a new open order. Listing 15.6 shows the completed prGetCustomerCart procedure. ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.