帮忙看看这个极其简单的存储过程什么地方错了.
日期:2007-07-05 荐:
帮忙看看这个极其简单的存储过程什么地方错了.CREATE PROCEDURE proc_addweek@ci int ASselect dm,jiang_month=jiang2 jiang31 jiang4 jiang41 jiang6 jiang7 jiang_partner jiangleft-jiang77,jiangleft=case when jiang2 jiang31 jiang4 jiang41 jiang6 jiang7 jiang_partner jiangleft-jiang77<100 then jiang2 jiang31 jiang4 jiang41 jiang6 jiang7 jiang_partner jiangleft-jiang77 else 0 end into #user_weekfrom award where ci=@ciupdate a set a.jiang_month=b.jiang_month,a.jiangleft=a.jiangleft b.jiangleftfrom user1 a ,#user_week b where a.dm=b.dmGO需求.把Award表中的一些字段相加得出一个新的字段。然后把所得到的值更新到user1 这个表里的相应字段。条件是user1表里的dm等于award表里的dm值。还有就是如果award这些字段相加的值小于100就把这个值添加到user1的另外一个字段里面。如果大于100就不用填写了,直接填入0就可以了。我之前没有加入jiangleft的判断的时候,是正确的。可以把jiang_month计算出来并且更新到user1里面去 不过加上jiangleft以后,也没有提示出错。不过jiangleft没有计算出来。是不是我写得有问题呀。存储过程刚刚接触。大家帮帮忙了。帮顶一下!!!update a set jiang_month=b.jiang_month,jiangleft=a.jiangleft b.jiangleftfrom user1 a inner join #user_week b on a.dm=b.dmCREATE PROCEDURE proc_addweek @ci int ASbeginselect dm, jiang_month = ISNULL(jiang2,0) ISNULL(jiang31,0) ISNULL(jiang4,0) ISNULL(jiang41,0) ISNULL(jiang6,0) ISNULL(iang7,0) ISNULL(iang_partner,0) ISNULL(jiangleft,0) - ISNULL(jiang77,0), jiangleft = case when ISNULL(jiang2,0) ISNULL(jiang31,0) ISNULL(jiang4,0) ISNULL(jiang41,0) ISNULL(jiang6,0) ISNULL(jiang7,0) ISNULL(jiang_partner,0) ISNULL(jiangleft,0) - ISNULL(jiang77,0) < 100 then ISNULL(jiang2,0) ISNULL(jiang31,0) ISNULL(jiang4,0) ISNULL(jiang41,0) ISNULL(jiang6,0) ISNULL(jiang7,0) ISNULL(jiang_partner,0) ISNULL(jiangleft,0) - ISNULL(jiang77,0) else 0 end into #user_weekfrom award where ci=@ciBEGIN TRANupdate a set a.jiang_month = b.jiang_month, a.jiangleft = a.jiangleft b.jiangleftfrom user1 a ,#user_week b where a.dm=b.dmCOMMIT TRANend试一下一条语句的:update user1set user1.jiang_month=Award.jiang2 Award.jiang31 Award.jiang4 Award.jiang41 Award.jiang6 Award.jiang7 Award.jiang_partner Award.jiangleft-Award.jiang77,a.jiangleft = a.jiangleft case when Award.jiang2 Award.jiang31 Award.jiang4 Award.jiang41 Award.jiang6 Award.jiang7 Award.jiang_partner Award.jiangleft-Award.jiang77<100 then Award.jiang2 Award.jiang31 Award.jiang4 Award.jiang41 Award.jiang6 Award.jiang7 Award.jiang_partner Award.jiangleft-Award.jiang77 else 0 end from Awardwhere ci=@ci and Award.dm = user1.dm--如果相加的字段有NULL值要用isnull(字段,0)来转换Thank You.应该是存在null值,任何值与null值运算,结果都是未知的,所以应该要排除null得情况,加上isnull(字段,0)
标签: