What will be the output of

declare @t table(names varchar(MAX))
insert into @t
select 'Ram' union all
select 'Shyam' union all
select 'Jadhu' union all
select 'Madhu'


DECLARE @NamesList VARCHAR(8000);
SELECT @NamesList =
COALESCE(@NamesList + ', ', '') + CAST(names AS varchar(20))
FROM @t
SELECT CombinedResult = @NamesList UNION ALL SELECT NULL

 Posted by Rajnilari2015 on 11/7/2015 | Category: Sql Server Interview questions | Views: 310 | Points: 40
Select from following answers:
  1. Ram, Shyam, Jadhu, Madhu
  2. NULL
  3. Two rows.First row with Ram, Shyam, Jadhu, Madhu and second row with NULL
  4. Two rows.First row with Madhu,Jadhu,Shyam,Ram and second row with NULL
  5. All Above

Show Correct Answer


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response