日期:2014-05-17 浏览次数:20833 次
if object_id('[MO_TABLE]') is not null drop table [MO_TABLE]
go
create table [MO_TABLE] (编号 nvarchar(6),名称 nvarchar(6),产量 int,完成日期 datetime)
insert into [MO_TABLE]
select 'A01','车间A',900,'2013-06-10' union all
select 'A02','车间B',700,'2013-06-10' union all
select 'A01','车间A',600,'2013-06-11' union all
select 'A02','车间B',1300,'2013-06-11' union all
select 'A01','车间A',800,'2013-06-12' union all
select 'A02','车间B',600,'2013-06-12'
select * from [MO_TABLE]
declare @sql varchar(8000)
select @sql = isnull(@sql + '],[' , '') + CONVERT(VARCHAR(10),完成日期,120) from [MO_TABLE] group by CONVERT(VARCHAR(10),完成日期,120)