2
SQL SELECT查询这给使用sqlserver的2005和上述 合并多个行成一个单列 我有两个表,即(tb_master,tb_tasks)的Sql多行合并成单个行与特定的图案
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
试过这个查询
select tasks + ' , ' as 'data()' from tb_tasks for xml path('')
给人输出
XML
cooking food , Programing 2 hours , Attending meeting , Driving car , hangout with friends ,
我需要输出像
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
查询我试图提前
+1对于DDL和数据。 –
@BogdanSahlean:thnkx –