select * from BemsMonitoringPoint where ValueType = 0
select * from BemsMonitoringPoint where FacilityCode = 1390

select TOP 1  * from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396 order by CreatedDateTime desc

select  * from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396 order by CreatedDateTime desc

select MAX(CreatedDateTime), * from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396
select MAX(CreatedDateTime)  from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396

select *  from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396 and select in (MAX(CreatedDateTime)  = CreatedDateTime)

select *  from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396 and CreatedDateTime = (select MAX(CreatedDateTime)
from BemsMonitoringPointHistory15min where PropertyId = 10 and FacilityCode = 3396)

select *  from BemsControlPointHistory where CreateDateTime = (select MAX(CreateDateTime)
from BemsControlPointHistory )

select * from BemsMonitoringPointHistory15min where CreatedDateTime = '2015-08-17 15:00'
select * from BemsMonitoringPointHistoryDaily where FacilityCode = 1390
select * from CmFacilityTempSet
select * from CmFacility where FacilityTypeId = 1

select * from FmsBudgetCodeClass
select *, LEN(BudgetSeq) from FmsBudgetCodeClass
select BudgetClassId from FmsBudgetCodeClass
select * from FmsBudgetCodeClass where Depth = 0
select * from FmsBudgetDetailExecution

select * from FmsBudgetDetailExecution where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where Depth = 0)
select * from FmsBudgetDetailExecution where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where LEN(BudgetSeq) = 6)

select * from FmsBudgetDetailExecution where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where SUBSTRING(BudgetSeq,1,2) = '01')

select * from FmsBudgetDetailExecution where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where LEN(BudgetSeq) = 6 and 
SUBSTRING(BudgetSeq,1,2) = '05')

select year, Month, SUM(MonthlyExecution) from FmsBudgetDetailExecution 
where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where LEN(BudgetSeq) = 6 and 
SUBSTRING(BudgetSeq,1,2) = '01')
group by  year, Month

select year, Month, SUM(MonthlyExecution) from FmsBudgetDetailExecution 
where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where LEN(BudgetSeq) = 6 and 
SUBSTRING(BudgetSeq,1,2) = '02')
group by  year, Month

select year, Month, SUM(MonthlyExecution) from FmsBudgetDetailExecution 
where BudgetClassId in (select BudgetClassId from FmsBudgetCodeClass where LEN(BudgetSeq) = 6 and 
SUBSTRING(BudgetSeq,1,2) = '03')
group by  year, Month

select SUBSTRING(BudgetSeq,1,2) from FmsBudgetCodeClass
select BudgetSeq from FmsBudgetCodeClass


select * from FmsBudgetDetailExecution where Year >= 1000 and Month > 0 and Year < 2016 or (Year = 2016 and Month < 5)
 select * from CmDepartment
 

 select * from FmsInvestmentCost
 select SUM(InsvestmentCost) from FmsInvestmentCost

 select * from FmsWorkRequest where WorkProgressId = 6
 select * from FmsWorkResult where IsConfirmed = 1

 select * from FmsWorkRequest where WorkProgressId = 3 or WorkProgressId = 4 or WorkProgressId = 5 or (WorkProgressId = 6 and 
 WorkRequestId in (select WorkRequestId from FmsWorkResult where IsConfirmed = 1 and ConfirmedDate > '2015 09 01'))

 select * from FmsWorkResult

 select * from FmsWorkRequest where (WorkProgressId = 6 and 
 WorkRequestId in (select WorkRequestId from FmsWorkResult where IsConfirmed = 1 and ConfirmedDate > '2015 09 01'))

 select * from FmsWorkOrder where BusinessFieldId = 1
 
 select * from FmsWorkResult where WorkRequestId in (select WorkRequestId  from FmsWorkRequest where 
 WorkProgressId = 4 )  and WorkerUserId = 'im'
 
  select * from FmsWorkOrder where WorkRequestId in (select WorkRequestId  from FmsWorkRequest where 
 WorkProgressId = 4 )  and BusinessFieldId = 2
 order by WorkRequestId

 select * from FmsWorkOrder where WorkRequestId in (select WorkRequestId  from FmsWorkRequest where 
 WorkProgressId = 3 or WorkProgressId = 4 )  and BusinessFieldId = 2
 order by WorkRequestId

 select * from FmsWorkOrder where WorkRequestId in (select WorkRequestId  from FmsWorkRequest where 
 WorkProgressId = 3 )  and BusinessFieldId = 2
 order by WorkRequestId

  select * from FmsWorkOrder where WorkRequestId in (select WorkRequestId  from FmsWorkRequest where 
 WorkProgressId = 4 )  and BusinessFieldId = 2
 order by WorkRequestId


  select * from FmsWorkOrder O where O.WorkRequestId in (select A.WorkRequestId  from FmsWorkRequest A,  FmsWorkResult B where 
 A.WorkProgressId = 3 or A.WorkProgressId = 4 and B.WorkerUserId = 'im')
 and O.BusinessFieldId = 2
 order by O.WorkRequestId

 select * from FmsWorkOrder where WorkRequestId in (select WorkRequestId from FmsWorkRequest where WorkProgressId= 3)
 and BusinessFieldId = 5
 order by WorkRequestId

 select * from FmsWorkOrder where WorkRequestId in (select WorkRequestId from FmsWorkRequest where WorkProgressId = 4)
 and BusinessFieldId = 5
 order by WorkRequestId

 select * from FmsWorkOrder where BusinessFieldId = 5 or BusinessFieldId = 1
 


 select * from FmsMaterialStored group by MaterialId
  select * from FmsMaterial where MaterialId = 3042 
 select * from FmsMaterialStored where MaterialId = 3042 and StoredDate = (select MAX(StoredDate) from FmsMaterialStored where MaterialId = 3042) 
 select * from FmsMaterialStored where MaterialId = 3042 and StoredDate = (select MAX(StoredDate) from FmsMaterialStored where MaterialId = 3042) 
 select * from FmsMaterialRelease where MaterialId = 3068 
 //3077 ����100  3076����
 select * from FmsMaterialRelease where MaterialId = 3076 
 select * from FmsMaterialStored where MaterialId = 3076
 
 select SUM(RemainStoredCount) from FmsMaterialStored where MaterialId = 3077 group by WarehouseId
 select SUM(RemainStoredCount) from FmsMaterialStored where WarehouseId = 1

 select MaterialId, SUM(RemainStoredCount) from FmsMaterialStored where WarehouseId = 1 group by MaterialId
 select WarehouseId, MaterialId, SUM(RemainStoredCount) from FmsMaterialStored  group by WarehouseId, MaterialId

 select * from FmsMaterialRelease where MaterialId = 3068 

select * from BemsMonitoringPointHistory15min where CreatedDateTime = '2015 10 05 14:30:00' and PropertyId = 17
//update BemsMonitoringPointHistory15min set CurrentValue = 100 where CreatedDateTime = '2015 10 05 14:30:00' and PropertyId = 17
select * from BemsMonitoringPointHistory15min where CreatedDateTime = '2015 10 05 14:30:00' and PropertyId = 17

select * from BemsMonitoringPointHistoryDaily where FacilityCode = 4863  and PropertyId = 2 and CreatedDateTime = '2016 03 18'
select * from BemsMonitoringPointHistoryDaily where FacilityCode = 4863  and PropertyId = 1 and CreatedDateTime = '2016 03 18'

// 2016 04 19
select * from BemsMonitoringPoint where ServiceTypeId = 100
select * from BemsMonitoringPointHistoryHourly where PropertyId = 3 and CreatedDateTime > '2016 04 18' and FacilityCode = 4499
select * from CmFacility where FacilityCode = 4499
select ApplyDate from BemsNoticePriceDetail 
select Max (ApplyDate), * from BemsNoticePriceDetail where ApplyDate <= '2016 04 01'
select * from BemsNoticePriceDetail where ApplyDate <= '2014 04 01'

select * from BemsNoticePriceDetail where ApplyDate = (select Max (ApplyDate) from BemsNoticePriceDetail where ApplyDate <= '2016 04 01')
and FuelTypeId = 1 and ContractType = 1

select * from BemsNoticePriceDetail where ApplyDate = (select Max (ApplyDate) from BemsNoticePriceDetail where ApplyDate <= '2016 04 01')
and FuelTypeId = 1 and ContractType = 1

select AVG(P07) from BemsNoticePriceDetail where ApplyDate = (select Max (ApplyDate) from BemsNoticePriceDetail where ApplyDate <= '2016 04 01')
and FuelTypeId = 1 and ContractType = 1