September 7, 2007 at 2:40 pm
Can I have an optional parameter within an SP? If so, what is the syntax (how do I declare it)?
Sam
September 7, 2007 at 10:17 pm
Yes, you can... best way to learn this one is to look up CREATE PROCEDURE in Books Online and read about it
--Jeff Moden
Change is inevitable... Change for the better is not.
September 19, 2007 at 8:53 am
Sam,
Here is a very basic example using an optional paramater. The parameter @title is given a default value so users do not have to pass in a value unless they want a different result set.
USE Northwind
GO
CREATE PROCEDURE dbo.nwSample
@Title nvarchar(30) ='Sales Representative'
AS
SELECT LastName, FirstName, Title, HireDate
FROM dbo.Employees
WHERE Title = @title
--Then try
exec nwSample --no paramater
exec nwSample 'Sales Manager' --with parameter
--DROP PROCEDURE nwSample
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply