我现在想在gridview里面绑定
数据库里是
会考证件 姓名 课程名称
100101070242 刘XX 语文
100101070242 刘XX 英语
100101070242 刘XX 汉语
100101070243 王麻子 英语
100101070243 王麻子 西班牙语言
gridview里显示 我想
会考证件 姓名 课程名称
100101070242 刘XX 语文,英语,汉语
100101070243 王麻子 英语,西班牙语言
数据库里是
会考证件 姓名 课程名称
100101070242 刘XX 语文
100101070242 刘XX 英语
100101070242 刘XX 汉语
100101070243 王麻子 英语
100101070243 王麻子 西班牙语言
gridview里显示 我想
会考证件 姓名 课程名称
100101070242 刘XX 语文,英语,汉语
100101070243 王麻子 英语,西班牙语言
会考证件,姓名
stuff((select ','+课程名称 from 表 where 会考证件=T.会考证件 for xml path('')),1,1,'') as 课程名称
from 表 AS T
group by 会考证件,姓名
stuff((select ','+课程名称 from 表 where 会考证件=T.会考证件 for xml path('')),1,1,'') as 课程名称
from 表 AS T
group by T.会考证件, T.姓名
if object_id('[tb]') is not null drop table [tb]
create table [tb]([id] varchar(12),[name] varchar(12),[class] varchar(12))insert [tb]
select '100101070242','刘XX','语文' union all
select '100101070242','刘XX','英语' union all
select '100101070242','刘XX','汉语' union all
select '100101070243','王麻子','英语' union all
select '100101070243','王麻子','西班牙语言' select * from tbselect T.id,T.name,stuff((select ','+class from tb where id=T.id for xml path('')),1,1,'') as nclassame
from tb AS T group by T.id, T.name2000这样写也是可以的啊
create function func(
@col1 varchar(10)
)returns varchar(100)
as
begin
declare @re varchar(100)
set @re=''
select
@re=@re+','+cast(class as varchar)
from tb
where [name]=@col1
return stuff(@re,1,1,'')
end 然后
if object_id('[tb]') is not null drop table [tb]
create table [tb]([id] varchar(12),[name] varchar(12),[class] varchar(12))insert [tb]
select '100101070242','刘XX','语文' union all
select '100101070242','刘XX','英语' union all
select '100101070242','刘XX','汉语' union all
select '100101070243','王麻子','英语' union all
select '100101070243','王麻子','西班牙语言'
select id,[name],class=dbo.func(name)
from tb
group by [name],id
http://topic.csdn.net/u/20090508/12/1c02cc61-3634-481a-9a45-8bfe514e3060.html