Multiple choice technology databases

What is the output? DECLARE @val CHAR(20) SET @val = ' SQL is cool ' select LEN(@val)

  1. 20

  2. 14

  3. 12

  4. 13

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In SQL Server, the LEN function returns the number of characters in a string, excluding trailing spaces. The string ' SQL is cool ' has 1 leading space and 11 characters ('SQL is cool'), totaling 12. The trailing space is ignored by LEN.

AI explanation

To answer this question, you need to understand the LEN function in SQL.

The LEN function is used to return the number of characters in a specified string. In this case, the specified string is the variable @val, which is set to ' SQL is cool '.

The LEN function will count all characters in the string, including leading and trailing spaces. Therefore, the output of the query select LEN(@val) will be the total number of characters in the string, which is 12.

So, the correct answer is C) 12.