Multiple Choice Questions - SQL Server Cast & Convert
1. ........ conversions are those conversions that occur without specifying either the CAST or CONVERT function.
A) Explicit
B) Implicit
C) Variant
D) Parse
2.
DECLARE @Var_1 INT = 1000000000 DECLARE @Var_2 INT = 1000000028 DECLARE @Var_3 REAL Set @Var_3=@Var_2 SELECT CASE WHEN @Var_3 = @Var_1 THEN 'True! These numbers are equal' ELSE 'False! These numbers are not equal' END AS [Result], CONVERT(INT, @Var_3) as [Result - Var_3 as an int], @Var_3 as [Result - Var_3]What will be the value of above query:
A)
Result - True! These numbers are equal
Result - Var_3 as an int 1000000000
Result - Var_3 1E+09
B)
Result - False! These numbers are not equal
Result - Var_3 as an int 1000000000
Result - Var_3 1E+09
C)
It will show an error message!
D)
None of above
3. ...... is the ANSI-standard and ...... is specific to SQL SERVER.
A) Convert, Cast
B) Cast, Cast
C) Convert, Convert
D) Cast, Convert
4. When the output of CAST or CONVERT is a character string, and the input is a character string, the output has the same ...... as the input.
A) Result
B) Expression
C) Collation
D) None of above
5. Choose the correct syntax of Cast & Convert:
A) CONVERT (expression AS data_type)
B) CAST (data_type [ (length) ] , expression [ , style ] )
C) CAST (expression AS data_type)
D) CONVERT (data_type [ (length) ] , expression [ , style ] )
6. SQL Server guarantees that roundtrip conversions, that convert a data type from its original data type and back again, will always yield the same values from version to version.
A) True
B) False
7.
SELECT CAST(10.6496 AS int);
SELECT CAST(10.6496 AS money);
SELECT CAST(10.6496 AS smallmoney);
Which one of below depicts the correct result of above three queries:
A) 10, 10.6496, 10
B) 10.6496, 10.6496, 10
C) 10, 10.6496, 10.6496
D) 10.6496, 10.6496, 10.6496
8. SQL Server returns an error when an empty string (" ") is converted to decimal, but works fine in case of numeric.
A) True
B) False
9.
DECLARE @var NVARCHAR(10) = 23
SELECT Cast (@var AS NVARCHAR(1));
What is the result of above query:
A) 23
B) 2
C) NULL
D) None of above
10.
SELECT CONVERT(CHAR(10), CURRENT_TIMESTAMP, 102)
SELECT CAST(CONVERT(CHAR(10),CURRENT_TIMESTAMP,102) As DATETIME)
What is the result of above two queries:
A) 2014.08.22, 2014-08-22 00:00:00.000
B) 2014-08-22 00:00:00.000, 2014.08.22
C) 2014.08.22, 2014.08.22
D) 2014-08-22 00:00:00.000, 2014-08-22 00:00:00.000
Answers