Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
select min(MH.sno) as hatchid,(SH.name+'-'+SH1.name) as    hatcheryname, convert(varchar,SD.settingdate,103)as settingdate,
     sum(SD.Recievedeggs) as eggsdispatchqty, sum(SD.quantity) as   settingqty, convert(varchar,MH.pulloutdate,103) as Pulloutdate, SD.batchno as flockno,
    sum(MH.ChicksQnty) as Noofchicks, sum(MH.culls) as culls, cast((round((((MH.ChicksQnty-  MH.culls)/SD.quantity)*100),2)) as float) as hatchpercent, 
    sum(cast(round(((SD.quantity*87)/100),0)as int)) as ActSalablechicks, sum((MH.Chicksqnty-  MH.culls))as Salablechicks from K_HM_SetterGetterAllocationDet SD
     inner join K_HM_SetterDetails MS on SD.sno=MS.ID
     inner join K_HM_HatcherDetails HD on MS.sno=HD.ID
     inner join K_HM_MasterHatcherdet MH on HD.Sno=MH.ID
     inner join K_HM_GetterSetterDet SH on SD.name=SH.sno
     inner join K_HM_GetterSetterDet SH1 on SH1.sno=HD.hatchername  where    HD.attrited='true'
     and MH.pulloutdate is not null and MS.pulloutdate is not null  group by
     MH.sno,SH.name,SH1.name,SD.settingdate,MH.pulloutdate,SD.batchno,
     MH.Chicksqnty,MH.culls,SD.quantity order by settingdate desc


I have four different tables data,these four tables have some relation one to one.Actually what i want is depending settingdate column,some sum(column) of columns . I have tried like this but it is showing different rows not showing sum of row. How can i write please help me out. Thanks in advance
Posted
Updated 25-Apr-14 3:58am
v3
Comments
Herman<T>.Instance 25-Apr-14 8:55am    
some sum(column) of columns -> or doy ou want some sum(column) of rows?
Your question is not clear. What is your exact problem?
thatraja 25-Apr-14 8:57am    
Update your question with sample output values which could help experts to give you quick answer
santhu888 25-Apr-14 9:00am    
I want different columns sum like sum(a),sum(b) of rows
santhu888 25-Apr-14 9:03am    
date recievedeggs settingeggs pulloutdate floctno chicks culls hatchpercent actualchicks salable

04/11/2013 15000 13500 26/11/2013 3 11000 100 80.74 11745 10900
thatraja 25-Apr-14 10:32am    
update those details in your question

1 solution

Try to change it this way:
SQL
SELECT min(MH.sno) as hatchid,(SH.name+'-'+SH1.name) as    hatcheryname, convert(varchar,SD.settingdate,103)as settingdate,
     sum(SD.Recievedeggs) as eggsdispatchqty, sum(SD.quantity) as   settingqty, convert(varchar,MH.pulloutdate,103) as Pulloutdate, SD.batchno as flockno,
    sum(MH.ChicksQnty) as Noofchicks, sum(MH.culls) as culls, cast((round((((MH.ChicksQnty-  MH.culls)/SD.quantity)*100),2)) as float) as hatchpercent,
    sum(cast(round(((SD.quantity*87)/100),0)as int)) as ActSalablechicks, sum((MH.Chicksqnty-  MH.culls))as Salablechicks from K_HM_SetterGetterAllocationDet SD
     inner join K_HM_SetterDetails MS on SD.sno=MS.ID
     inner join K_HM_HatcherDetails HD on MS.sno=HD.ID
     inner join K_HM_MasterHatcherdet MH on HD.Sno=MH.ID
     inner join K_HM_GetterSetterDet SH on SD.name=SH.sno
     inner join K_HM_GetterSetterDet SH1 on SH1.sno=HD.hatchername  where    HD.attrited='true'
     and MH.pulloutdate is not null and MS.pulloutdate is not null
GROUP BY (SH.name+'-'+SH1.name), convert(varchar,SD.settingdate,103), convert(varchar,MH.pulloutdate,103), SD.batchno,
ORDER BY CONVERT(DATETIME, CONVERT(varchar,SD.settingdate,103)) DESC
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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