
select count(*) from MeterSessionInput
left join Meter on MeterSessionInput.MeterKey = Meter.MeterKey
left join Customer on Meter.CustomerKey = Customer.CustomerKey
where MeterSessionInput.MeterSessionInputKey
not in
(select MetersessionInputKey from MeterSessionOutput)


select 
substring(AccountNumber,1, 11) as AccountNo,
Meter.MeterNumber,
FullStreetAddress,
FullName,
Meter.UtilityMeterSequenceNumber,
case  Meter.MeterCategory
when 4 then 'Water'
when 1 then 'Gas'
end as 'MeterType',
MeterSessionOutput.ReadDateTime as DateTime,
MeterSessionOutput.ReadCode as ReadCode,
MeterSessionOutput.ReadCondition as ReadCondition,
MeterSessionInput.PreviousRead as PreviousRead,
CASE 
WHEN ISNUMERIC(MeterSessionOutput.ReadFormatted) = 1 
THEN CAST(MeterSessionOutput.ReadFormatted AS INT) 
ELSE NULL END as CurrentRead,
CurrentRead - PreviousRead
from MeterSessionInput
left join Meter on MeterSessionInput.MeterKey = Meter.MeterKey
left join Customer on Meter.CustomerKey = Customer.CustomerKey
left join MeterSessionOutput on MeterSessionInput.MeterSessionInputKey = MeterSessionOutput.MeterSessionInputKey




