3.7 Executing the Stored Procedure

To run the stored procedure, enter this line of SQL:

exec get_product

This is the output:

product_id product_name start_date
1 Pink Widget 2007 Jan 1 2007
3 Gray Widget 2005 Jan 1 2005

The keyword exec is short for execute. You could also have typed execute get_product.

Alternatively, you can just type the procedure name

get_product

For this last option to work, the procedure must be the only statement in the batch or be the first statement in the batch. For example, this works:

get_product
select getdate() as 'current_date'

But the next listing will output an error: : incorrect syntax near 'get_product'.

select getdate() as 'current_date'
get_product

We will use the exec keyword throughout the book to avoid confusion.