564 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
SQL stored procedures and passing parameters Part three of a six-part series of blogs |
---|
Stored procedures are programs in SQL which allow you to pass parameters to queries and manipulate sets of rows in tables. Find out how to write them with this online training blog!
This blog is part of a complete SQL Server tutorial. |
Let's suppose that you've created the stored procedure described in the previous part of this blog:
CREATE PROC spListActors
AS
-- display list of actors
SELECT
ActorName,
ActorGender
FROM
tblActor
You now want to run the spListActors stored procedure, to list out its contents. Below are 3 ways to do this.
The simplest way to run a stored procedure is just to select its name and press F5:
Just double-click on the name of the stored procedure to select it, and then execute it like any other SQL query.
This will produce the results of the SELECT statement included in the procedure:
The first few rows returned by running the procedure.
Note that this method doesn't work if your stored procedure takes parameters (then again, we haven't covered parameters yet!).
A second way to run a stored procedure is to right-click on its name:
Right-click on the name of the procedure in SQL Server Management Studio and choose to execute it as shown here.
Again, this method doesn't work well if your stored procedure takes parameters.
The third way to run a stored procedure is to use the EXECUTE command within a query:
-- 3 ways to run procedure to list out actors
EXEC spListActors
GO
EXECUTE spListActors
GO
spListActors
GO
As the above examples show, you can abbreviate EXECUTE to EXEC or - under certain circumstances - miss it out altogether.
Parts of this blog |
---|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.