In order to carry its assignment, a function can be
provided with some values. Put it another way, when you create a function,
instead of, or in addition to, local variables, you may want the code that
will call the function to provide the values needed to perform the
assignment. For example, imagine you want to create a function that would
generate employees email addresses when a user has entered a first and last
name. At the time you are creating the function, you cannot know or
predict the names of
employees, including those who have not even been hired yet. In this case,
you can write the whole function but provide one or more placeholders for
values that would be supplied when the function is called.

An external value that is provided to a
function is called a parameter. A function can also take more than one
parameter. Therefore, when you create a function, you also decide whether
your function would take one or more parameters and what those parameters,
if any, would be.

A Parameterized Function

We have already seen that a function's name is also
followed by parentheses. If the function doesn't use an external value,
its parentheses can be left empty. If a function will use an external
value, when you create the function, you must specify a name and the type
of value of the parameters. The name of the parameter is created with the @
sign, like a variable as we saw in the previous lesson. Here is an example:

CREATE FUNCTION Addition(@Number1 Decimal(6,2))

When a function takes a parameter, in the body of the
function, you can use the parameter as if you knew its value, as long as
you respect the type of that value. Here is an example:

When you call a function that takes one parameter, you
must supply a value for that argument. To do this, type the value of the
parameter in the parentheses of the function. Here is an example:

A Function With Various Arguments

Instead of only one parameter, you can also create a
function that takes more than one parameter. In this case, separate the
arguments in the parentheses of the function with a comma. Here is an
example:

Once again, in the body of the function, you can use
the parameters as if you already knew their value. You can also declare
local variables and involve them with parameters as you see fit. Here is an
example:

When calling a function that takes more than one
parameter, in the parentheses of the function, provide a value for each
parameter, in the exact order they appear in the parentheses of the
function. Here is an example:

PRINT Variables1.dbo.Addition(1450, 228);

You can also pass the names of already declared and
initialized variables. Here is an example that calls the above function:

Write a function named ProcessPayroll1 that takes the number of hours
worked in a week. Then the function returns a value that represents
overtime. If the employee worked less than 40 hours, there is no overtime.
If the employee worked for more than 40 hours, the number over 40 is
considered overtime

Write a function named GetWeekdayName that, when given a date, can find and display the name of
the week for that date

Write a function named GetNumberDays that takes two dates and returns the
number of days between them

Write a function named AddNumberDays that takes a date and an integer,
then it returns the date added that number