Database Reference
In-Depth Information
Figure 6-4.
Using an output parameter
How It Works
You added an output parameter,
@TitleCount
, like this:
Create procedure sp_CountContacts_By_Title
@Title nvarchar(8),
@TitleCount int= 0 output
As
You assigned it a default value of zero. The keyword
output
marks it as an output parameter. You
also added an additional query:
select Contact.Title, Contact.FirstName, Contact.LastName
from Person.Contact
where Contact.Title = @Title
You assigned the scalar returned by the new query to the output parameter in the
SELECT
list:
@TitleCount = count(*)then you returned the same value
return @TitleCount