.NET 与存储过程


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

1,传参与调用:
?SqlParameter[] storedParams = {
????????????????????????????????????????????? new SqlParameter(“@TranType”, “INSERT”),
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? new SqlParameter(“@RoleName”, _RoleEntity.RoleName),
????????????????????????????????????????????? new SqlParameter(“@description”, _RoleEntity.Description),
????????????????????????????????????????????? new SqlParameter(“@CreateBy”, _RoleEntity.CreateBy),
????????????????????????????????????????????? new SqlParameter(“@isValid”, _RoleEntity.IsValid),
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? new SqlParameter(“@isSystem”, _RoleEntity.IsSystem),???????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????? //new SqlParameter(“@LastEditBy”, _RoleEntity.LastEditBy),
?????????????????????????????????????????????
????????????????????????????????????????? };

??????????????? _RoleEntity.ID = int.Parse(SqlHelper.ExecuteScalar(HelpConstant.DBCONN_STRING,
??????????????????? CommandType.StoredProcedure,?????? //指定按存储过程执行
??????????????????? “frmRole_save”,?????????????????????????????? //存储过程名称
??????????????????? storedParams).ToString());
传的参数小于等于存储过程指定的参数个数,不能有存储过程不存在的参数。

2,存储过程技巧
????? 1,AND OrderNo LIKE ISNULL(@OrderNo, ”) + ‘%’? // 有则查,无查全部
????? 2, AND CONVERT(varchar(10), OrderDate, 20) =, //AND 语句中加入选择!
??? ??? CASE(ISNULL(@OrderDate, ”))
??? ??? ??? WHEN ” THEN? CONVERT(varchar(10), OrderDate, 20)
??? ??? ??? ELSE @OrderDate END
上面的可直接换成下面方式:先计算出值再查询
?IF ( @CustomerName IS NULL )
??? BEGIN
??? ??? SET @CustomerName = ”
??? END
?IF ( @ShipDateEnd IS NULL OR @ShipDateEnd = ” )
??? BEGIN
??? ??? SET @ShipDateEnd = ‘2999-01-01′
??? END???

3, 右连接对指定的条件进行聚合
SELECT DISTINCT ACCOUNT, a.departmentid,sum(a.amount) as amount FROM bdOrder a
RIGHT JOIN permUserDepartment p
on a.SalesStaff = p.Account
AND a.orderstatus = ’07’
where?? a.DepartmentID is null or a.DepartmentID IN (SELECT DepartmentID FROM permUserDepartment(NOLOCK)??? WHERE Account = ‘sa’)? — 销售部门
group by account,a.departmentid
order by account,a.departmentid