我想计算除了sql server中的一个条件之外的列值? [英] i want to calculate column value except one condition in sql server?

查看:148
本文介绍了我想计算除了sql server中的一个条件之外的列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALTER proc [dbo].[K_RT_DateMeatTallyBasedGrid]
      @sno int
      as
      begin

    select PN.partyname,Round(DT.totalweight,2) as   totalweight,BT.BirdName,DT.rateperkg,DT.dcno,round((DT.totalweight*DT.rateperkg),2)as totalamount from K_RT_Dailyentryretail DT
    inner join  K_RT_PartyName PN on PN.sno=DT.partyname
    inner join K_RT_BirdType  BT on BT.sno=DT.BirdType
    inner join K_RT_WarehouseDetails WD on DT.branchdate=WD.sno
    where DT.branchdate=@sno order by  WD.[date] desc

    end



i希望得到圆((DT.totalweight * DT.rateperkg),2)作为totalamount这个输出但是partyname ='ClosingStock',那个时候我不想算我怎么写请帮帮我....


i want to get "round((DT.totalweight*DT.rateperkg),2)as totalamount" this out put but partyname='ClosingStock', at that time i don't want to calculate how can i write please help me....

推荐答案

所以你想不包括来自closestock的值?这不是一个总数,所以你可以用例:



so you want to not include the values from closingstock ? This is not a total, so you can use case:

select case when partyname = 'ClosingStock' then 0 else round((DT.totalweight*DT.rateperkg),2) end as totalAmount





只需将其插入到您的select语句中你刚才有的计算



Just plug that in to your select statement instead of just the calculation you have now


use case condition

ALTER proc [dbo].[K_RT_DateMeatTallyBasedGrid]
      @sno int
      as
      begin
 
    select PN.partyname,Round(DT.totalweight,2) as   totalweight,
           BT.BirdName,DT.rateperkg,DT.dcno,
           CASE WHEN partyname='ClosingStock' THEN 0 
           ELSE round((DT.totalweight*DT.rateperkg),2) 
           END AS totalamount 
    from K_RT_Dailyentryretail DT
    inner join  K_RT_PartyName PN on PN.sno=DT.partyname
    inner join K_RT_BirdType  BT on BT.sno=DT.BirdType
    inner join K_RT_WarehouseDetails WD on DT.branchdate=WD.sno
    where DT.branchdate=@sno order by  WD.[date] desc
 
    end

may be it will help u


这篇关于我想计算除了sql server中的一个条件之外的列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆