日期:2014-05-17 浏览次数:21019 次
DataClasses1DataContext db = new DataClasses1DataContext();
foreach(int key in db.Attendances.Select(s => s.LocationId).Distinct()
{
Console.Write(key);
foreach(string text in db.Attendances.Where(s => s.LocationId == key).Select(s => s.Text))
{
Console.Write(text);
}
}
create table tb(id int ,context varchar(10))
insert into tb
select 1,'a1'
union all select 1,'a2'
union all select 1,'a3'
union all select 2,'b1'
union all select 3,'c1'
union all select 3,'c2'
go
create function dbo.fn_b(@id int)
returns varchar(1000)
as
begin
declare @s varchar(1000)
set @s=''
select @s=@s+' '+context from tb where id=@id
return (@s)
end
go
select id,dbo.fn_b(id) as context
from tb
group by id
/*
id context
---------------------------
1 a1 a2 a3
2 b1
3 c1 c2
*/