C# 查询sql返回值为单个或者数组


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[]>();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM