行列转换
2007-11-16 15:47 澜心 阅读(351) 评论(0) 编辑 收藏 举报 //查询人员信息的sql语句
string UsrSql = "select distinct proid,proname from v_ProjectAndUserInfo "+ con;
DataTable UserDt = GetTable(UsrSql);
StringBuilder sBuilder = new StringBuilder();
sBuilder.Append("SELECT disname as '姓名',");
foreach(DataRow row in UserDt.Rows)
{
string GUID = row["proid"].ToString();
string Name = row["proname"].ToString();
sBuilder.Append("SUM(CASE proid WHEN '" + GUID + "' THEN workhours ELSE 0 END) AS '" + Name + "',");
}
string Ssql = sBuilder.ToString() + "(SELECT SUM(workhours)) AS '合计' ";
DataTable dt = getCountResult(Ssql,con);
string UsrSql = "select distinct proid,proname from v_ProjectAndUserInfo "+ con;
DataTable UserDt = GetTable(UsrSql);
StringBuilder sBuilder = new StringBuilder();
sBuilder.Append("SELECT disname as '姓名',");
foreach(DataRow row in UserDt.Rows)
{
string GUID = row["proid"].ToString();
string Name = row["proname"].ToString();
sBuilder.Append("SUM(CASE proid WHEN '" + GUID + "' THEN workhours ELSE 0 END) AS '" + Name + "',");
}
string Ssql = sBuilder.ToString() + "(SELECT SUM(workhours)) AS '合计' ";
DataTable dt = getCountResult(Ssql,con);