Select chapter



Basics (2.papers)
Data Types (2.papers)
Table-designing (1.papers)
Queries-Commands (3.papers)
String functions (2.papers)
Subqueries (1.papers)
Joins (1.papers)
Constraints (1.papers)
Triggers (1.papers)
Hide

Sponsored Links


  

sql string functions interview questions and answers

Please read the below given table for solving questions from 1 to 6
eidfnamelnameagesalarydeptdoj
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM
2sowmyakumari2319000db13-Nov-10 12:00:00 AM
3kishorekumar2736000android16-Oct-11 12:00:00 AM
4abimanyubiswal22nullandroid25-May-10 12:00:00 AM
5sonikumar2421800.net21-Jun-09 12:00:00 AM
6anu_singh2212000db23-Oct-10 12:00:00 AM
7_dineshmoh%anty2315000.net26-Aug-09 12:00:00 AM
8nischala_kumari2218000db19-Jul-08 12:00:00 AM
9gouravchourasia2420000android06-Oct-13 12:00:00 AM
Note: Assume table is present in a database named skillgun , the Schema name is dbo and the table name as Employees ;
1
Which of the following query can be used for displaying full names of all the employees in the reverse order?
  1. select REVERSE(upper(fname+lname)) from employees
  2. select upper(reverse(fname+lname)) from employees
  3. select upper(reverse(lname))+upper(reverse(fname)) from employees
  4. All the queries are correct
Show Answer
Share Facebook gmail Twitter
2
Identify the correct query for displaying the full names (fname+lname) of all the employees in the descending order of the total number of characters present in the full name?
  1. select fname+lname as fullname from employees order by LEN(fname+lname) desc
  2. select fname+lname as fullname from employees order by LEN(fullname)
  3. select fname+lname as fullname,len(fname+lname) from employees
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
3
Which of the following query can be used for displaying all the employees fnames whose fnames are having more than 6 characters ?
  1. select fname from employees where len(fname)=6
  2. select fname from employees having len(fname)>6
  3. select fname from employees where len(fname)>6
  4. None of the above
Show Answer
Share Facebook gmail Twitter
4
What is the output of the following query?
Query: select substring(fname,2,3) as result from employees
  1. query will produce parsing error.
  2. result
    aje
    owm
    ish
    bim
    oni
    nu
    din
    isc
    our
    aje
  3. (no column name)
    aje
    owm
    ish
    bim
    oni
    nu
    din
    isc
    our
    aje
  4. None of the above
Show Answer
Share Facebook gmail Twitter
5
Which of the following query can be used for displaying the total ascii values of all the characters present in each fname?
Expected result set :
asciivalue
660
930
730
324
441
854
757
672
637
  1. declare @totalrows int;
    select @totalrows=COUNT(*) from employees ;
    declare @emps table (eid int );
    insert into @emps select eid from employees ;
    declare @asciivalues table (asciival int );
    while(@totalrows>0)
    begin
    declare @maxeid int;
    select @maxeid=MAX(eid) from employees ;
    declare @length int;
    select @length=LEN(fname) from employees where eid=@maxeid;
    declare @asciitotalval int ;
      while(@length>0)
      begin
      declare @currentchar varchar(1);
      select @currentchar=SUBSTRING(fname,@length,1) from employees where eid=@maxeid;
      set @length=@length-1;
      set @asciitotalval=@asciitotalval+ascii(@currentchar);
      end
      insert into @asciivalues values (@asciitotalval);
      set @asciitotalval=0;
    delete @emps where eid=@maxeid;
    --select ASCII(fname) from employees
    set @totalrows=@totalrows-1;
    select * from @asciivalues;
    end
  2. declare @totalrows int;
    select @totalrows=COUNT(*) from employees ;
    declare @emps table (eid int );
    insert into @emps select distinct eid from employees ;
    declare @asciivalues table (asciival int );
    while(@totalrows>0)
    begin
    declare @maxeid int;
    select @maxeid=MAX(eid) from @emps ;
    declare @length int;
    select @length=LEN(fname) from employees where eid=@maxeid;
    declare @asciitotalval int ;
    set @asciitotalval=0;
      while(@length>0)
      begin
      declare @currentchar varchar(1);
      select @currentchar=SUBSTRING(fname,@length,1) from employees where eid=@maxeid;
      set @length=@length-1;
      set @asciitotalval=@asciitotalval+ascii(@currentchar);
      end
      if(@asciitotalval<>0)
      insert into @asciivalues values (@asciitotalval);
      set @asciitotalval=0;
    delete @emps where eid=@maxeid;
    --select ASCII(fname) from employees
    set @totalrows=@totalrows-1;
    end
    select * from @asciivalues;
Show Answer
Share Facebook gmail Twitter
6
Which of the following query can be used for display all the employees fnames excluding the first and last character in each fname ?
Expected result set :
  1. select substring(fname,2,LEN(fname)-2) from employees
  2. select substring(fname,2) from employees
  3. select substring(fname,1,len(fname)-1) from employees
  4. None of the above
Show Answer
Share Facebook gmail Twitter
Read more papers :