Home » SQL SERVER Interview Q & A QUIZ on SUBSTRING()

SQL SERVER Interview Q & A QUIZ on SUBSTRING()

Q 1 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , 11 ,3) as output

1> ‘Microsoft’

2> ‘SQL’

3> BLANK

4> Invalid Substring statement

Answer

2> ‘SQL’

 

Q 2 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , 11 ,0) as output

1> ‘Microsoft’

2> ‘SQL’

3> BLANK

4> ‘SQL SERVER’

Answer

2> BLANK

 

 

Q 3 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , -1 ,9) as output

1> ‘Microso’

2> ‘SQL’

3> BLANK

4> ‘SQL SERVER’

Answer

1> ‘Microso’

 

Q 4 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , 1 ,9) as output

1> ‘Microsoft’

2> ‘Microsof’

3> BLANK

4> ‘SQL SERVER’

Answer

1> ‘Microsoft’

 

 

Q 5 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT ‘SQL ‘ + SUBSTRING( @stringtxt , 15 ,6) as output

1> ‘SQL  SQL SERVER’

2> ‘SQL SER’

3> BLANK

4> ‘SQL SERVER’

Answer

4> ‘SQL SERVER’

 

 

Q 6 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt +‘ SQL’ , 15 ,6) as output

1> ‘SQL SER’

2> ‘SQL SERVER’

3> BLANK

4> ‘SERVER’

Answer

4> ‘SERVER’

 

 

Q 7 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , 11 ,Len(@stringtxt)-10) as output

1> ‘Microsoft SQL SERVER’

2> ‘SQL SERVER’

3> ‘Microsoft’

4> Invalid Syntax

Answer

2> ‘SQL SERVER’

 

 

Q 8 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , null , null)  as output

1> ‘SQL SERVER SQL’

2> ‘SQL SERVER’

3> null

4> ‘Microsoft SQL SERVER’

Answer

3> null

 

 

Q 9 > 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , 0 ,0) as output

1> ‘Microsoft’

2> ‘SQL’

3> BLANK

4> ‘SQL SERVER’

Answer

2> BLANK

 

 

Q 10> 

DECLARE @stringtxt as varchar(20)
SET @stringtxt=‘Microsoft SQL SERVER’

SELECT SUBSTRING( @stringtxt , null , null)  as output

1> ‘SQL SERVER SQL’

2> ‘SQL SERVER’

3> null

4> ‘Microsoft SQL SERVER’

Answer

3> null

 

 

Recommended Posts..

SQL Substring()

SQL Interview Q & A Quiz on Select Statement

SQL Interview Q & A Quiz on Create statement

Leave a Reply

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