有F和T两张表
t表有两列数据
Name 和 Indexe
设备1 代号1
设备2 2
设备3 3
f表有3列数据
DAte Indexe Val
01:33:34 1 234
01:33:34 2 352.86792
01:33:34 3 .875628456
02:34:35 1 252
02:34:35 2 287.86874
02:34:35 3 .875623576
``````````````````````````
想自动生成Excel
n表每天一张格式如下
时间 设备1 设备2 设备3
01 234 352.86 0.875
02 252 287.86 0.875
''''''
24 ''' '''''' '''''
另求一位老师(精通sql自动化的不通过别的软件来实现)
t表有两列数据
Name 和 Indexe
设备1 代号1
设备2 2
设备3 3
f表有3列数据
DAte Indexe Val
01:33:34 1 234
01:33:34 2 352.86792
01:33:34 3 .875628456
02:34:35 1 252
02:34:35 2 287.86874
02:34:35 3 .875623576
``````````````````````````
想自动生成Excel
n表每天一张格式如下
时间 设备1 设备2 设备3
01 234 352.86 0.875
02 252 287.86 0.875
''''''
24 ''' '''''' '''''
另求一位老师(精通sql自动化的不通过别的软件来实现)
insert into t select '設備1',1
insert into t select '設備2',2
insert into t select '設備3',3create table f([date] datetime,indexe int,val float)
insert into f select '01:33:34',1,234
insert into f select '01:33:34',2,352.86792
insert into f select '01:33:34',3,0.875628456
insert into f select '02:34:35',1,252
insert into f select '02:34:35',2,287.86874
insert into f select '02:34:35',3,0.875623576
select t.[name],f.* into temp_t from t inner join f on t.indexe=f.indexe
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+',sum(case when [name]='''+[name]+''' then val end) as '+[name] from temp_t group by [name]
select @sql=' select convert(char(02),[date],108) as 時間'+@sql+' from temp_t group by convert(char(02),[date],108)'
exec(@sql)drop table temp_t
drop table t
drop table f時間 設備1 設備2 設備3
----------------------------------------------------
01 234.0 352.86792000000003 0.87562845600000005
02 252.0 287.86874 0.87562357599999996
想每天出一個excel,可以將這個寫成store procedure,然後(SQL2000)用DTS來call,轉成excel,
讓系統每天自動跑該DTS就可以了