为了提高效率,不妨写函数来对数据量较大的统计工作,例如:
CREATE FUNCTION fun_CountSiteGroupTotal
(
)
RETURNS int
AS
BEGIN
declare @countNum int
select @countNum=Count(*) from Com_SiteGroup where EngineeringState=1
return @countNum
END
GO
select dbo.fun_CountSiteGroupTotal() --调用函数
//在orm中调用函数
var resutl = DataAccess.LepulsDB.DBContext.ExecuteScalar(System.Data.CommandType.Text, "select dbo.fun_CountSiteGroupTotal()");