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
549 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 ==> | Scalar functions (9 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.
This will generate the database that you'll need to use in order to do this exercise (note that the database and script are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl).
Strangely there is no function that can return the name of a month when given a number 1 to 12. Luckily for you that is exactly what we will do (the rest of this exercise explains how!).
The function you make will only produce one month name. When it's working properly try looping through number 1 to 12.
The layout for creating a function is very close to that for a stored procedure with a parameter, but with an extra part to specify the data type returned:
CREATE FUNCTION FunctionName
(@Para1 Datatype)
RETURNS Datatype
AS
BEGIN
RETURN
--The calculation goes here
END
To turn a month number into a month name we need to recreate a DATE to do that use the following code.
There are any number of ways to return the month name - feel free to use a different one.
Test that your function is working by passing in several month numbers separately.
Optionally save this as Month Name function.sql and 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.