Note that there are some explanatory texts on larger screens.

plurals
  1. POSql Multiple row merge into single row with specific pattern
    primarykey
    data
    text
    <p>Sql select query which gives merge multiple row into one single row using sqlserver 2005 and above I have two tables ie <strong>(tb_master,tb_tasks)</strong></p> <pre><code>create table tb_tasks( id int IDENTITY(1,1) NOT NULL, id_tbmaster int NOT NULL, Tasks nvarchar(max) NOT NULL ) create table tb_master( id int IDENTITY(1,1) NOT NULL, grade nchar(10) NOT NULL, name nvarchar(50) NOT NULL, task_date datetime NOT NULL, ) select * from tb_master id grade name task_date 1 A John 2012-02-13 10:40:00.000 2 B Tom 2012-02-13 10:40:00.000 select tb_tasks id id_tbmaster Tasks 1 1 cooking food. 2 1 Programing 2 hours 3 1 Attending meeting 4 2 Driving car 5 2 hangout with friends </code></pre> <p>Have tried this query</p> <pre><code>select tasks + ' , ' as 'data()' from tb_tasks for xml path('') </code></pre> <p>Gives Output</p> <pre><code>XML cooking food , Programing 2 hours , Attending meeting , Driving car , hangout with friends , </code></pre> <p><strong>I need output like</strong> </p> <pre><code>id Name grade task_date tasksDetails 1 John A 2012-02-13 10:40:00.000 1)cooking food, 2)Programing 2 hours, 3)Attending meeting 2 Tom B 2012-02-13 10:40:00.000 1) Driving car, 2)hangout with friends </code></pre> <p>Query i tried</p> <pre><code>select a.name,a.task_date,b.tasks =replace(select (CONVERT(VARCHAR,(ROW_NUMBER() OVER(ORDER BY id DESC)))) + ') ' + tasks + ' , ' as 'data()' from tb_tasks for xml path('')) from tb_master a inner join tb_tasks b on a.id=b.id_tbmaster </code></pre> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload