1.当返回值为单个的时候
string sql = string.Format("SELECT end_code FROM v_power_year_area_item WHERE meter_name = '{0}' AND stat_time >= '{1}'", DeviceName, DateTime.Now.ToString("yyyy-01-01 00:00:00")); var yearList = SysLogRunningDao.GetSession().CreateSQLQuery(sql).List<object>();
2.当返回值为数组的时候
string yearTime0 = DateTime.Now.ToString("yyyy-01-01 00:00:00");//本年第一天凌晨 string yearSql = string.Format("SELECT t1.fieldName,t1.itemValue,t2.sumlValue,( t1.itemValue/ t2.sumlValue * 100 ) AS percentValue from (SELECT t0.fieldName ,SUM ( t0.total_used ) as itemValue FROM (SELECT*,LEFT ( meter_name, 2 ) AS fieldName FROM {0} WHERE stat_time >='{1}') AS t0 GROUP BY t0.fieldName)as t1,( SELECT SUM ( total_used ) AS sumlValue FROM {0} WHERE stat_time >= '{1}' ) AS t2 ORDER BY percentValue DESC", "v_power_month_area_item", yearTime0); var yearList = SysLogRunningDao.GetSession().CreateSQLQuery(yearSql).List<object[]>();