Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
562 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers 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 ...
Software ==> | SQL (203 exercises) |
Topic ==> | Parameters and return values (17 exercises) |
Level ==> | Relatively easy |
Subject ==> | SQL training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
If you don't have a copy of the Music_01 database, follow the instructions at the following link to create it: www.wiseowl.co.uk/sql/exercises/standard/using-sql-server/5257/
Open the Tracks of My Years.sql file in the folder shown above. Execute the script to create two stored procedures.
The usp_Get_Top_Album_ID procedure shows the ID of the top-selling album in whichever year you pass into its parameter. Create a new script and write code to execute this procedure.
Here's the ID of the top-selling album from 1980.
The usp_Show_Album_Details procedure shows the details of an album whose ID you pass into its parameter.
This is what we get if we ask for the details of album 97.
Currently, the usp_Get_Top_Album_ID procedure only shows the value of the album ID. We want the procedure to RETURN the value so that we can capture it in a variable.
Alter the usp_Get_Top_Album_ID procedure and add the RETURN keyword in front of the SELECT statement. Wrap the SELECT statement in round brackets and execute the script to update the procedure.
The start of the query should look like this.
In your test script, declare an INT variable called @TopAlbumID and use it to capture the return value of the usp_Get_Top_Album_ID procedure. Here's a reminder of the syntax to do this:
EXEC @MyVariable = My_Stored_Proc
Now pass the ID of the album stored in the variable to the parameter of the usp_Show_Album_Details procedure.
Execute the test script to check the results. You can use any year from 1964 to 2023.
Definitely not England's newest any longer!
Save the scripts and then close them.
You can find other training resources for the subject of this exercise here:
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 2024. All Rights Reserved.