Статья в первую очередь является подсказкой для меня, поэтому привожу пример конкретной ситуации.
Ситуация следующая, один набор данных на сервер работающем под управлением ПО "Пирамида 2000. Сервер", база данных MS SQL Server, второй набор данных находится на сервере под управлением ПО "КТС Энергомера 2.7", база данных Oracle.
Если в статье затрагиваю чей-то интерес, писать сюда: palem[dog]list[dot]ru.
string sqlP2kQuery = sqlGetP2kData;
string sqlKtsQuery = sqlGetKtsData;
DataTable tblP2k = dbManager.sqlConnector.ExecQuery(sqlP2kQuery);
DataTable tblKts = dbManager.oraConnector.ExecQuery(sqlKtsQuery);
DataTable resTable = dbManager.TablePlusTable(tblP2k, tblKts);
dgv1.DataSource = resTable;
dgv1.Update();
Ситуация следующая, один набор данных на сервер работающем под управлением ПО "Пирамида 2000. Сервер", база данных MS SQL Server, второй набор данных находится на сервере под управлением ПО "КТС Энергомера 2.7", база данных Oracle.
Если в статье затрагиваю чей-то интерес, писать сюда: palem[dog]list[dot]ru.
string sqlP2kQuery = sqlGetP2kData;
string sqlKtsQuery = sqlGetKtsData;
DataTable tblP2k = dbManager.sqlConnector.ExecQuery(sqlP2kQuery);
DataTable tblKts = dbManager.oraConnector.ExecQuery(sqlKtsQuery);
DataTable resTable = dbManager.TablePlusTable(tblP2k, tblKts);
dgv1.DataSource = resTable;
dgv1.Update();
~~~ Запрос 1. К базе данных MS SQL Server (sqlGetP2kData)
if OBJECT_ID('tempdb..#telNumber', 'U') is not null
if OBJECT_ID('tempdb..#telNumber', 'U') is not null
drop table #telNumber
select
STATIONID,
substring(CONNECTSTR, 4, 11) as TelNumber
into
#telNumber
from
ICMROUTES
where
VIRTPORT = 1
select
STATIONID,
substring(CONNECTSTR, 4, 11) as TelNumber
into
#telNumber
from
ICMROUTES
where
VIRTPORT = 1
if OBJECT_ID('tempdb..#const', 'U') is not null
drop table tempdb..#const
select
const.ITEMID,
CAST(const.CONSTANTTEXT AS NUMERIC(38, 0)) as value
into
tempdb..#const
from
CONSTANTS as const
drop table tempdb..#const
select
const.ITEMID,
CAST(const.CONSTANTTEXT AS NUMERIC(38, 0)) as value
into
tempdb..#const
from
CONSTANTS as const
where
const.CONSTANTTYPE = 8
if OBJECT_ID('tempdb..#values', 'U') is not null
drop table #values
select
*
into
#values
from
Piramida2000.dbo.DATA
where
(Piramida2000.dbo.DATA.DATA_DATE = '28.04.2014')
and
(Piramida2000.dbo.DATA.PARNUMBER = 101)
and
(Piramida2000.dbo.DATA.ITEM = 2)
select
convert(varchar(100), 'p2k') as SERVTYPE,
convert(varchar(100), Folders.ID) as FOLDERID,
convert(varchar(100), DEVICES.CODE) as DEVICECODE,
convert(varchar(100), DEVICES.NAME) as OBJECTNAME,
convert(varchar(100), 'CE303') as METERTYPE,
convert(varchar(100), tempdb..#const.value) as SN,
convert(varchar(100), dog.dog) as DOG,
convert(varchar(100), #telNumber.TelNumber) as TELNUMBER,
convert(varchar(100), '26.02.2014') as DATETIME,
convert(varchar(100), 'A-') as ENTYPE,
convert(varchar(100), Cast(tempdb..#values.VALUE0 as decimal(38, 3))) as KWTCH
from
const.CONSTANTTYPE = 8
if OBJECT_ID('tempdb..#values', 'U') is not null
drop table #values
select
*
into
#values
from
Piramida2000.dbo.DATA
where
(Piramida2000.dbo.DATA.DATA_DATE = '28.04.2014')
and
(Piramida2000.dbo.DATA.PARNUMBER = 101)
and
(Piramida2000.dbo.DATA.ITEM = 2)
select
convert(varchar(100), 'p2k') as SERVTYPE,
convert(varchar(100), Folders.ID) as FOLDERID,
convert(varchar(100), DEVICES.CODE) as DEVICECODE,
convert(varchar(100), DEVICES.NAME) as OBJECTNAME,
convert(varchar(100), 'CE303') as METERTYPE,
convert(varchar(100), tempdb..#const.value) as SN,
convert(varchar(100), dog.dog) as DOG,
convert(varchar(100), #telNumber.TelNumber) as TELNUMBER,
convert(varchar(100), '26.02.2014') as DATETIME,
convert(varchar(100), 'A-') as ENTYPE,
convert(varchar(100), Cast(tempdb..#values.VALUE0 as decimal(38, 3))) as KWTCH
from
Piramida2000.dbo.DEVICES
join
Piramida2000.dbo.FOLDERS on DEVICES.FOLDERID = FOLDERS.ID
left join
tempdb..#values on DEVICES.CODE = #values.OBJECT
left join
tempdb..#const on DEVICES.ID = #const.ITEMID
left join
#telNumber on DEVICES.ID = #telNumber.STATIONID
left join
dogovor as dog on (cast(#const.value as varchar(20)) = cast(dog.SN as varchar(20)))
order by Devices.NAME
join
Piramida2000.dbo.FOLDERS on DEVICES.FOLDERID = FOLDERS.ID
left join
tempdb..#values on DEVICES.CODE = #values.OBJECT
left join
tempdb..#const on DEVICES.ID = #const.ITEMID
left join
#telNumber on DEVICES.ID = #telNumber.STATIONID
left join
dogovor as dog on (cast(#const.value as varchar(20)) = cast(dog.SN as varchar(20)))
order by Devices.NAME
~~~ Запрос 2. К базе данных Oracle (sqlGetKtsData)
select
TO_CHAR('kts') SERVTYPE ,
TO_CHAR(dsrobj.dcid) FOLDERID,
TO_CHAR(devs.devinc) DEVICECODE,
TO_CHAR(dsrobj.name) OBJECTNAME,
TO_CHAR('CE201') METERTYPE,
TO_CHAR(devs.sernum) SN,
TO_CHAR('') DOG,
TO_CHAR('') TELNUMBER,
'28.04.2014' datetime,
TO_CHAR('A-') EnType,
TO_CHAR(cdi.val, '9999.999') kWtCh
from
devices devs
join
dsrobj on (dsrobj.dcid = devs.dcid) and (dsrobj.objid = devs.objid)
left join
cdi on (cdi.devid = devs.devinc) and (cdi.tariffid = 0) and (cdi.reliable = 3) and (cdi.stamp = to_date('28.04.2014', 'DD.MM.YY'))
Комментариев нет:
Отправить комментарий