The real power of stored procedures is the ability to pass parameters and have the stored procedure handle the differing requests that are made. In this topic we will look at passing parameter values to a stored procedure.
Explanation:
Just like you have the ability to use parameters with your SQL code you can also setup your stored procedures to accept one or more parameter values.
One Parameter:
In this example we will query the Person.Address table from the AdventureWorks database, but instead of getting back all records we will limit it to just a particular city. This example assumes there will be an exact match on the City value that is passed.
USE AdventureWorks
GO
CREATE PROCEDURE dbo.uspGetAddress @City nvarchar(30)
AS
SELECT *
FROM Person.Address
WHERE City = @City
GO
To call this stored procedure we would execute it as follows:
EXEC dbo.uspGetAddress @City = 'New York'
Share This with your friend by choosing any social account