-2
我在Visual Studio中使用此查詢。我想添加另一列,將我找到的字段(History
,Acts
,Forms
和Documents
)合計爲每個工作人員的Total
。我試圖添加Sum,但效果不佳。如何向我的SQL查詢添加總和?
我該怎麼做?
sqlcmd.CommandText = "use odlight select e1.fullname as worker,acts,forms,documents,history from opg.dbo.vwemployee as e1 " +
" left outer join (select tsCreatedBy ,count(actid) as acts from hozactions as h1 where ((h1.tscreatedate between '" + date1 + "' and '" + date2 + "') or (h1.tsModifydate between '" + date1 + "' and '" + date2 + "')) group by tsCreatedBy) as t1 on e1.UserID= t1.tsCreatedBy " +
" left outer join (select tsCreatedBy ,count(*) as forms from TikForms as t1,SysForms as s1 where t1.FormCounter=s1.Counter and t1.actioncounter in ('0','-1') and tsCreateDate between '" + date1 + "' and '" + date2 + "' group by tsCreatedBy) as t2 on e1.UserID=t2.tsCreatedBy " +
" left outer join (select tsCreatedBy,count(*) as documents from Documents where createDate between '" + date1 + "' and '" + date2 + "' group by tsCreatedBy) as t3 on e1.UserID=t3.tsCreatedBy " +
" left outer join (select tsCreatedBy,count(*) as history from nispah where tscreatedate between '" + date1 + "' and '" + date2 + "' group by tsCreatedBy) as t5 on e1.UserID=t5.tsCreatedBy " +
" where e1.DepartmentCode not in (6,2,4,10) and e1.Active =1 order by e1.fullname ";
決不連接字符串創建SQL查詢。這是一個安全隱患。改爲使用參數化查詢。 –