MCQs on Functions and Expressions | SQL Server

In this set of 30 multiple-choice questions (MCQs), we cover essential SQL Server functions and expressions, including Aggregate Functions (SUM, AVG, COUNT), String Functions (LEN, CONCAT), Date Functions (GETDATE, DATEADD), and Mathematical Functions. These questions are ideal for beginners and intermediate learners to test their SQL knowledge and understanding of SQL Server functions.

Aggregate Functions

  1. Which of the following is used to calculate the total sum of values in a column in SQL Server?
    • A) COUNT
    • B) AVG
    • C) SUM
    • D) MIN
  2. What does the COUNT function do in SQL Server?
    • A) Adds the values
    • B) Returns the number of rows
    • C) Finds the average value
    • D) Returns the highest value
  3. What will the AVG function return when used on a column of numerical values?
    • A) The sum of all values
    • B) The median of values
    • C) The average of values
    • D) The minimum value
  4. Which function can be used to get the maximum value in a column?
    • A) MAX
    • B) MIN
    • C) COUNT
    • D) SUM
  5. Which of the following functions does not consider NULL values in SQL Server?
    • A) SUM
    • B) COUNT
    • C) AVG
    • D) MAX
  6. What is the return type of the COUNT function when used on a numeric column?
    • A) Integer
    • B) Decimal
    • C) Float
    • D) String
  7. Which aggregate function will return the smallest value in a column?
    • A) MAX
    • B) SUM
    • C) MIN
    • D) COUNT
  8. What is the purpose of the GROUP BY clause in aggregate functions?
    • A) Filters records based on condition
    • B) Groups records into summary
    • C) Sorts records in ascending order
    • D) Joins two tables together

String Functions

  1. Which function in SQL Server is used to concatenate two or more strings?
    • A) LEN
    • B) CONCAT
    • C) SUBSTRING
    • D) CHARINDEX
  2. The LEN function returns the length of a string excluding which of the following?
    • A) Spaces at the beginning
    • B) Spaces at the end
    • C) Punctuation marks
    • D) All spaces
  3. Which function returns the position of a substring within a string?
    • A) SUBSTRING
    • B) CHARINDEX
    • C) CONCAT
    • D) REPLACE
  4. What does the LEFT function do in SQL Server?
    • A) Returns characters from the end of the string
    • B) Returns characters from the beginning of the string
    • C) Removes the first character of the string
    • D) Changes the case of the string
  5. Which function is used to replace a substring within a string in SQL Server?
    • A) REPLACE
    • B) CHARINDEX
    • C) CONCAT
    • D) LEFT
  6. The TRIM function is used to remove which characters from a string?
    • A) Extra spaces only
    • B) Special characters only
    • C) Leading and trailing spaces
    • D) Punctuation marks
  7. What is the return value of the UPPER function in SQL Server?
    • A) Converts a string to lowercase
    • B) Converts a string to uppercase
    • C) Returns the length of a string
    • D) Reverses the string
  8. The RIGHT function in SQL Server is used to:
    • A) Extract characters from the left side of the string
    • B) Extract characters from the right side of the string
    • C) Replace characters in the string
    • D) Convert string to uppercase

Date Functions

  1. Which SQL Server function is used to get the current date and time?
    • A) GETDATE
    • B) CURRENT_DATE
    • C) NOW
    • D) DATEADD
  2. What will the DATEADD function do in SQL Server?
    • A) Adds or subtracts a specified time interval to a date
    • B) Returns only the date part of a date-time value
    • C) Converts a string to a date
    • D) Extracts a part of a date (like year, month)
  3. Which function can be used to extract the year from a date in SQL Server?
    • A) YEAR
    • B) MONTH
    • C) DAY
    • D) GETDATE
  4. What does the DATEDIFF function do?
    • A) Finds the difference between two dates
    • B) Adds two dates together
    • C) Converts a date to a string
    • D) Returns the current date
  5. Which function returns the current system date in SQL Server?
    • A) SYSDATETIME
    • B) GETDATE
    • C) NOW
    • D) CURRENT_TIMESTAMP
  6. What does the DATEPART function do in SQL Server?
    • A) Extracts a part of the date (e.g., month, day)
    • B) Converts a date into a specific format
    • C) Returns the total number of days in a month
    • D) Calculates the number of seconds between two dates
  7. How does the CURRENT_TIMESTAMP function behave in SQL Server?
    • A) Returns the date with no time component
    • B) Returns the current date and time of the system
    • C) Adds a specified interval to the date
    • D) Converts a string to a timestamp
  8. The GETDATE function returns the date and time of the system in which format?
    • A) yyyy-mm-dd
    • B) mm-dd-yyyy
    • C) yyyy-mm-dd hh:mm:ss
    • D) dd-mm-yyyy
  9. Which function can you use to add months to a given date in SQL Server?
    • A) DATEADD
    • B) MONTH
    • C) GETDATE
    • D) DATEDIFF

Mathematical Functions

  1. Which function in SQL Server returns the absolute value of a number?
    • A) ABS
    • B) ROUND
    • C) CEILING
    • D) FLOOR
  2. The CEILING function in SQL Server returns:
    • A) The highest integer greater than or equal to a number
    • B) The lowest integer greater than or equal to a number
    • C) The square root of a number
    • D) The integer part of a number
  3. What does the FLOOR function do in SQL Server?
    • A) Returns the nearest whole number greater than or equal to the value
    • B) Returns the nearest whole number less than or equal to the value
    • C) Returns the absolute value of a number
    • D) Rounds a number to the nearest integer
  4. Which SQL Server function can be used to round a number to a specified number of decimal places?
    • A) ROUND
    • B) ABS
    • C) CEILING
    • D) FLOOR
  5. Which function is used to return the square root of a number in SQL Server?
    • A) POWER
    • B) SQRT
    • C) EXP
    • D) LOG

Answer Key

QnoAnswer
1C) SUM
2B) Returns the number of rows
3C) The average of values
4A) MAX
5B) COUNT
6A) Integer
7C) MIN
8B) Groups records into summary
9B) CONCAT
10B) Spaces at the end
11B) CHARINDEX
12B) Returns characters from the beginning of the string
13A) REPLACE
14C) Leading and trailing spaces
15B) Converts a string to uppercase
16B) Extract characters from the right side of the string
17A) GETDATE
18A) Adds or subtracts a specified time interval to a date
19A) YEAR
20A) Finds the difference between two dates
21B) GETDATE
22A) Extracts a part of the date (e.g., month, day)
23B) Returns the current date and time of the system
24C) yyyy-mm-dd hh:mm:ss
25A) DATEADD
26A) ABS
27A) The highest integer greater than or equal to a number
28B) Returns the nearest whole number less than or equal to the value
29A) ROUND
30B) SQRT

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top