--拼sql吧create table t1 (id int ,name varchar(100)) insert into t1 values (1,'AAA') create table AAA(id int) insert into AAA values (10)declare @Tname varchar(50) set @Tname='' select @Tname=Name from t1 where id =1 print @Tname declare @sql varchar(max) set @sql='select * from '+@Tname+' where id =10' print @sql exec(@sql)
你可以創建1個view,這view包含各個傳感器檢測數據,再通過sql語句關鍵查詢即可 E.g.View 內容: select ID, [时间],[检测值],'DS001' as [传感器名称] from DS001 union all select ID, [时间],[检测值],'DS002' as [传感器名称] from DS002 union all select ID, [时间],[检测值],'DS003' as [传感器名称] from DS003 union all select ID, [时间],[检测值],'DS004' as [传感器名称] from DS004 union all .... ....然後 Select: select ... from viewName .... inner join ....當然還有使用動態sql,先把每一個傳感器某1時間點的數據值找出來,放到1個臨時表,然後對臨時表進行關聯和select即可。
insert into t1 values (1,'AAA')
create table AAA(id int)
insert into AAA values (10)declare @Tname varchar(50)
set @Tname=''
select @Tname=Name from t1 where id =1
print @Tname
declare @sql varchar(max)
set @sql='select * from '+@Tname+' where id =10'
print @sql
exec(@sql)
E.g.View 內容:
select ID, [时间],[检测值],'DS001' as [传感器名称] from DS001 union all
select ID, [时间],[检测值],'DS002' as [传感器名称] from DS002 union all
select ID, [时间],[检测值],'DS003' as [传感器名称] from DS003 union all
select ID, [时间],[检测值],'DS004' as [传感器名称] from DS004 union all
.... ....然後 Select:
select ...
from viewName ....
inner join ....當然還有使用動態sql,先把每一個傳感器某1時間點的數據值找出來,放到1個臨時表,然後對臨時表進行關聯和select即可。