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
545 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 ==> | Table-valued functions (8 exercises) |
Level ==> | Average difficulty |
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.
First (if you haven't already done so) run the script shown above to generate the Doctor Who training database.
Create a function to list out the episodes for any given series number and part of an author name. This could begin:
CREATE FUNCTION fnChosenEpisodes(
@SeriesNumber int,
@AuthorName varchar(100)
)
RETURNS TABLE
AS
For example, you could run this SQL query:
SELECT * FROM dbo.fnChosenEpisodes(1,'russell')
This would show the 9 series one episodes written by Russell T. Davies:
The first 2 or 3 of the 9 episodes in series 1 written by Russell T. Davies
Functions can't have optional parameters, but you can pass dummy values and detect them. Amend your function so that it shows:
To help you know whether you've succeeded, here's what 4 possible combinations should show:
-- there is 1 episode written by Steven Moffat for series 2
SELECT COUNT(*) FROM dbo.fnChosenEpisodes(2,'moffat')
-- -- there are 14 episodes in series 2 (for any author)
SELECT COUNT(*) FROM dbo.fnChosenEpisodes(2,null)
-- there are 32 episodes written by Steven Moffat (for any series)
SELECT COUNT(*) FROM dbo.fnChosenEpisodes(null,'moffat')
-- there are 117 episodes (any series, any author)
SELECT COUNT(*) FROM dbo.fnChosenEpisodes(null,null)
Optionally, save your query as Series and author.sql, then close it down.
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.