【发布时间】:2015-10-07 06:42:15
【问题描述】:
在我的 sql 存储过程中,我选择了更多列,我想找到列 NetAmount 的值的总和。只需要找到该列的总和。 以及其他选定的列值。这个怎么选?
为此,我将这样的代码[计算总和(gensal.NetAmount)],这是有效的,但无法通过实体框架为我的 Windows 应用程序选择此值。
这是一个带有可选参数的搜索查询 @EmpId、@MonthId、@YearId
我的代码是:-
ALTER PROCEDURE [dbo].[SP_SearchSalaryReport]
@EmpId int=null,
@MonthId int=null,
@YearId int=null
AS
BEGIN
SET NOCOUNT ON;
SELECT ed.Name,
desig.Designation,
mon.Month,
gensal.Year,
gensal.BasicPay,
gensal.CasualWorkedDays,
gensal.CasualWorkedAmount,
gensal.ApsentDays,
gensal.ApsentDaysAmount,
gensal.NetAmount
--SUM(gensal.NetAmount)[sum]
from dbo.Tbl_GenerateSalary gensal join
dbo.Tbl_Designation desig on gensal.DesignationId=desig.RecordId join
dbo.Tbl_EmployeeDetails ed on gensal.EmpId=ed.RecordId join
dbo.Tbl_Month mon on gensal.Month=mon.RecordId
where(isnull(@EmpId,0)=0 or gensal.recordId=@EmpId)
and(ISNULL(@MonthId,0)=0 or gensal.Month = @MonthId)
and(ISNULL(@YearId,0)=0) or gensal.Year = @YearId
compute sum(gensal.NetAmount)
END
【问题讨论】:
标签: winforms entity-framework sql-server-2008 stored-procedures