What will be the output of

declare @str as varchar(100)
declare @startposition int
declare @endposition int
declare @stopingcondition int
declare @delimeter char(1)
set @startposition = 0
set @stopingcondition = 10
set @delimeter =''
set @str = 'I would like to get word from a long sentence but not sure how to do this. I guess I should be looking for 15th space in the word but not sure how to do this could some please help?' -- original data

;with num_cte as
(
select 1 as rn
union all
select rn +1 as rn
from num_cte
where rn <= len(@str)
)
, get_all_delimited_char_pos_cte as
(
select row_number()over(order by rn) cnt ,rn,chars
from num_cte
cross apply( select substring(@str,rn,1) AS chars) splittedchars
where chars = @delimeter
)
select @endposition = rn from get_all_delimited_char_pos_cte where cnt = @stopingcondition
select SUBSTRING(@str,@startposition,@end

 Posted by Rajnilari2015 on 1/24/2016 | Category: Sql Server Interview questions | Views: 390 | Points: 40
Select from following answers:
  1. I would like to get word from a long sentence
  2. I would like to get word from a long sentence but
  3. I would like to get word from a long
  4. I would like to get word from a long sentence but not sure how to
  5. All Above

Show Correct Answer


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response