Home » SQL Q & A on SELECT Statement

SQL Q & A on SELECT Statement






Q 1 > SELECT Count(1) as Output

1> NULL

2> Error

3> 1

4> Invalid select statement

Answer

3 > 1

 

Q 2 > SELECT Count(*) as Output

1> NULL

2> 1

3> Error

4> Invalid select statement

Answer

2 > 1

 

Q 3 > SELECT Count(NULL) as Output

1> NULL

2> 1

3> Error

4> Operand data type NULL is invalid for count operator

Answer

4> Operand data type NULL is invalid for count operator

 

 

Q 4 > SELECT 1 as Value FROM (SELECT ‘A’ as a) AS tbl

1> NULL

2> 1

3> Error

4> Invalid Syntax

Answer

2> 1

 

Q 5 > SELECT SUM(NULL) as Total

1> NULL

2> 1

3> Operand data type NULL is invalid for sum operator

4> Invalid Syntax

Answer

3> Operand data type NULL is invalid for sum operator

 

 

Q 6 > SELECT 1 UNION select ‘A’

1> Conversion failed when converting the varchar value ‘A’ to data type int

2> A

3>VALUE
———
1
A

4>1

Answer

1> Conversion failed when converting the varchar value ‘A’ to data type int

 

 

Q 7 > SELECT 1 as Value UNION select ‘1’

1> Conversion failed when converting the varchar value ‘1’ to data type int

2> A

3> Error

4>1

Answer

4>1

 

 

Q 8 > SELECT 1 as VALUE UNION ALL SELECT 1 as VALUE

1> Conversion failed when converting the varchar value ‘1’ to data type int

2> VALUE
——–
1
1

3> Invalid syntax

4>1

Answer

2> VALUE
——–
1
1

 

 

Q 9 > SELECT 1 as val INTERSECT
( SELECT 1 val UNION ALL SELECT 2 )

1> 1

2> val
——–
1
2

3>  val
——–
1
2

4> Invalid Syntax Intersect

Answer

1 > 1

 

 

Q 10 > SELECT 5 as val EXCEPT
( SELECT 1 val )

1> 1

2> val
——–
1
5

3> 5

4> Invalid Syntax Except

Answer

3 > 5

 

 

Q 11 >  select 100 * 1.0 as val

1> 100.00

2>100

3> 100.0

4>Error

Answer

3 > 100.0

 

Q 12 > Select 1/case when null=null then 0 else 1 end as val

1> 1

2>0

3>Divide by zero error encountered.

4> Error

Answer

1> 1

 

 

Q 13 > Select 1/case when null=’0′ then 0 else 1 end as val

1> 1

2>0

3>Divide by zero error encountered.

4> Error

Answer

3>Divide by zero error encountered.

 

Watch SQL Server Advance & Basics tutorials on YouTube – SQL Server Tutorials

Recommended for you

SQL Select Statement

SQL Select Distinct

SQL Select Into Select 

SQL Select Into Select 

SQL Inerview Q & A Quiz on Substring function




Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.