hi all, i have three text files on a server which form a particular report. I also have the SQL query used to create the report for another division. I have tried to create the query in access to get around the "charge for service" model our IT team has adopted, but am not particularly gifted at reading SQL.
as i understand this, there are three tables, prefaced above by "e", "ero", & "emr". and these correspond to the text files. I get lost after this. can someone help me to replicate this query in access. the output from it is a simple spreadsheet listing the fields across the page.
Code:
SELECT
'/// select the following fields from 3 tables, "e", "ero", & "emr" (used twice)
e.UNIBIS_Equipment_Number,
e.Equipment_Number,
e.Equipment_Description,
ero.Operator_Code,
ero.Operator_Name,
emr_p.Meter_Reading_Date AS Previous_Meter_Reading_Date,
emr_p.Meter_Reading_Value AS Previous_Meter_Reading_Value,
emr_l.Meter_Reading_Date AS Current_Meter_Reading_Date,
emr_l.Meter_Reading_Value AS Current_Meter_Reading_Value,
CASE
'///identify which records
WHEN emr_p.Meter_Reading_Date IS NULL THEN
'///if date NULL, then 0
0
ELSE
DATEDIFF(DAY, emr_p.Meter_Reading_Date, emr_l.Meter_Reading_Date)
END AS Number_Days,
CASE
WHEN emr_p.Meter_Reading_Value IS NULL THEN
0
ELSE
(emr_l.Meter_Reading_Value - emr_p.Meter_Reading_Value)
END AS Number_Kilometers,
CASE
WHEN emr_p.Meter_Reading_Date IS NULL THEN
0
ELSE
ROUND((emr_l.Meter_Reading_Value - emr_p.Meter_Reading_Value) / DATEDIFF(DAY, emr_p.Meter_Reading_Date, emr_l.Meter_Reading_Date), 2)
END AS Average_per_Day
FROM
DW_ODS.dbo.T_UNIBIS_Equipment e
INNER JOIN
DW_ODS.dbo.T_UNIBIS_Equipment_Role_Operator ero
ON
e.UNIBIS_Equipment_Number = ero.UNIBIS_Equipment_Number
AND ero.Entity_Code <> '0NX'
AND ero.Role_Code = 'ADMIN'
INNER JOIN
(SELECT
emr.UNIBIS_Equipment_Number,
emr.Meter_Code,
emr.Meter_Reading_Date,
emr.Meter_Reading_Value
FROM
DW_ODS.dbo.T_UNIBIS_Equipment_Meter_Reading emr
INNER JOIN
(SELECT
UNIBIS_Equipment_Number,
Meter_Code,
MAX(Meter_Reading_Date) AS Meter_Reading_Date
FROM
DW_ODS.dbo.T_UNIBIS_Equipment_Meter_Reading
GROUP BY
UNIBIS_Equipment_Number,
Meter_Code) emr_mrd
ON
emr.UNIBIS_Equipment_Number = emr_mrd.UNIBIS_Equipment_Number
AND emr.Meter_Reading_Date = emr_mrd.Meter_Reading_Date
AND emr.Meter_Code = emr_mrd.Meter_Code) emr_l
ON
e.UNIBIS_Equipment_Number = emr_l.UNIBIS_Equipment_Number
AND emr_l.Meter_Code LIKE 'ODO%'
LEFT JOIN
(SELECT
emr.UNIBIS_Equipment_Number,
emr.Meter_Code,
emr.Meter_Reading_Date,
emr.Meter_Reading_Value
FROM
DW_ODS.dbo.T_UNIBIS_Equipment_Meter_Reading emr
INNER JOIN
(SELECT
emr.UNIBIS_Equipment_Number,
emr.Meter_Code,
MAX(emr.Meter_Reading_Date) AS Meter_Reading_Date
FROM
DW_ODS.dbo.T_UNIBIS_Equipment_Meter_Reading emr
INNER JOIN
(SELECT
UNIBIS_Equipment_Number,
Meter_Code,
MAX(Meter_Reading_Date) AS Meter_Reading_Date
FROM
DW_ODS.dbo.T_UNIBIS_Equipment_Meter_Reading
GROUP BY
UNIBIS_Equipment_Number,
Meter_Code) emr_mrd
ON
emr.UNIBIS_Equipment_Number = emr_mrd.UNIBIS_Equipment_Number
AND emr.Meter_Reading_Date < emr_mrd.Meter_Reading_Date
AND emr.Meter_Code = emr_mrd.Meter_Code
GROUP BY
emr.UNIBIS_Equipment_Number,
emr.Meter_Code) emr_prd
ON
emr.UNIBIS_Equipment_Number = emr_prd.UNIBIS_Equipment_Number
AND emr.Meter_Reading_Date = emr_prd.Meter_Reading_Date
AND emr.Meter_Code = emr_prd.Meter_Code) emr_p
ON
e.UNIBIS_Equipment_Number = emr_p.UNIBIS_Equipment_Number
AND emr_p.Meter_Code LIKE 'ODO%'
ORDER BY
e.UNIBIS_Equipment_Number
as i understand this, there are three tables, prefaced above by "e", "ero", & "emr". and these correspond to the text files. I get lost after this. can someone help me to replicate this query in access. the output from it is a simple spreadsheet listing the fields across the page.