Functions Flashcards

1
Q

What performs a simple operation on exactly two inputs?

A

A binary operator

5.6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax of a binary operator?

A

value1 operator value2

where value1 and value2 have similar data types.

(5.6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What can arithmetic operators be use with?

A

Numeric values

5.6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What 5 arithmetic operators does the training companion list?

A
  1. Addition ( + )
  2. Subtraction ( - )
  3. Multiplication ( * )
  4. Division ( / )
  5. Modulus: the remainder when one number is divided by another ( % )

(5.6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What arithmetic operator can be used to add whole or partial day (represented by a numeric value) to a date/time value?

A

The addition ( + ) operator

5.6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What arithmetic operator can be used to subtract whole or partial days (represented by a numeric value) to a date/time value?

A

The subtraction ( - ) operator

5.6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the concatenation operator and what does it do?

A

The concatenation operator ( + ) appends two string values together. If either value is null, the result is NULL.

(5.7)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define a function.

A

A function takes a number of inputs, also called argument, and returns some sort of output, also called a result.

(5.8)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does CURRENT_TIMESTAMP return?

A

The current date and time from the system. This is incredibly useful in comparing dates and lengths of time, such as in queries where you want to find all patient within a certain age range, or all new charges from last month.

(5.8)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the MONTH function argument?

A

A date.

Syntax: MONTH ( Date )
EX: Select MONTH (‘01-04-2009’)

(5.8)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the MONTH function return?

A

The month value from the date.

EX: Select MONTH (‘01-04-2009’)
=1

(5.8)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the DATEADD function argument?

A
  1. Interval (datepart)
  2. Number
  3. Date

EX: Select DATEADD (d, 15, ‘04 JAN 2009 23:42’) - - = 19 JAN 2009

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do functions require?

A

Arguments of the correct data type in the correct order.

For example, the DATEADD function requires one datepart, one number, and one date or datetime, in that order. Any invalid input will cause an error, and the query will not run.

(5.10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Does using a function in the SELECT clause create a new column in your results?

A

Yes.

5.10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Do functions with no arguments require parentheses?

A

No.

EX: Select CURRENT_TIMESTAMP “Current Date”

(5.11)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: In SQL, you can’t combine different types of data without first converting the data types to be compatible.

A

True (5.13)

17
Q

How is the datetime format returned?

A

With a time down to the millisecond.

5.14

18
Q

In SQL Server, what is the default length of the data type in the CAST function?

A

30.

5.13

19
Q

What does the CAST function do?

A

Changes data from one type to another.

5.13

20
Q

Is CONVERT similar to CAST?

A

The CONVERT function works similarly to the CAST function but is specific to SQL Server and has additional optional parameters.

(5.14)

21
Q

True or False;

When filtering based on dates, you will often need to use a range.

A

True

5.15

22
Q

What is the DATEDIFF syntax?

A

DATEDIFF (datepart, start date, end date)

5.16

23
Q

What are the arguments for DATEFROMPARTS?

A
  1. Year - an integer expression that specifies a year.
  2. Month - an integer expression that specifies a month, from 1 to 12
  3. Day - an integer expression that specifies a day.
24
Q

What function can control the number of decimal places returned?

A

The STR function.

5.17

25
Q

How would you append additional text to a column and have there be a space between the result and the appended text?

A

By leaving a space
• After the single quote
• Before the appended text

26
Q

What happens if just one of the values being concatenated is NULL?

A

The concatenation returns NULL.

5.19

27
Q

How many string_value arguments does the CONCAT function require?

A

At least two and no more than 254 string_value arguments.

28
Q

What does COALESCE return?

A

The first non-null input.

5.24

29
Q

How many arguments can COALESCE use?

A

As many as needed, but they all must be the same data type.

You can utilize CAST to convert a data type as necessary.

(5.20)

30
Q

What are three SQL Server functions for data type conversion?

A
  1. CAST
  2. CONVERT
  3. STR

(5.21)

31
Q

What are 8 SQL Server Date and Time functions?

A
  1. CURRENT_TIMESTAMP
  2. GETDATE( )
  3. DATEADD
  4. DATEFROMPARTS
  5. DAY
  6. MONTH
  7. YEAR
  8. DATEDIFF

(5.22)

32
Q

What are 4 SQL Server String functions?

A
  1. CONCAT
  2. LEN
  3. CHARINDEX
  4. SUBSTRING

(5.23)

33
Q

What are 2 SQL Server Null functions?

A
  1. COALESCE
  2. ISNULL

(5.24)