Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
SQL
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 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....
Posted

SQL
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
 
Share this answer
 
Comments
Christian Graus 4-Jan-14 2:06am    
*grin* same answer, at exactly the same second :-)
Renuka Ruke 4-Jan-14 2:08am    
S :)
Christian Graus 4-Jan-14 2:11am    
Yours is more copy and paste. I misread the question at first and was writing a CTE based solution.
Renuka Ruke 4-Jan-14 2:18am    
wht u mean by CTE based solution
Renuka Ruke 4-Jan-14 2:21am    
ohh my answer was accepted actually i am testing my knowledge :)
so you want to not include the values from closingstock ? This is not a total, so you can use case:

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


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900