SQL | Archived exercise | Function to get courses for given resource name

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.

Software ==> SQL  (198 exercises)
Version ==> Any version of SQL Server
Topic ==> Archived  (70 exercises)
Level ==> Average difficulty
Subject ==> SQL training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

If you haven't already done so, run the stored procedure in the above folder to generate a database of training courses and delegates.

Create a multi-statement table-valued function (!) called fnCoursesForResources which - given a particular resource name - will return a table of courses which use that resource.  Here's how this should work:

SQL exercise - Table-valued functions (image 1)

You can call the function with different resource names, to get different results

You may find it helpful to declare an integer variable called @ResourceId, and set this to hold the ID of the resource corresponding to the name passed in as an argument.  You can then test to see if this equals null (which would mean the resource didn't exist).

Here are the first 3 of the 79 rows the function should return for a Projector:

SQL exercise - Table-valued functions (image 2)

This assumes you sort the data by course start date

Optionally, save this query as Courses for horses.sql, then close it down.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post