Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have made a query in sqlserver. the code is below.

SQL
select ReceiptNo, S_Adm_No, paid_date, S_Adm_No, Class, S_Name, S_F_Name, Mode_Payment,ChqNo,ChqDated, bank_Name, For_the_Month , 
FHeadId, FHead,Fine, TotalAmount, Concession, payableAmount, SUM (Apr + May+Jun+Jul+Aug+Sep+Oct+Nov+[Dec]+Jan+Feb+Mar) as FEE 
from View_Fee_Receipt_Students where ReceiptNo='AIS/16-17/00096' group by ReceiptNo, 
S_Adm_No, paid_date, S_Adm_No, Class, S_Name, S_F_Name, Mode_Payment,ChqNo,ChqDated, bank_Name, For_the_Month ,
Fine, TotalAmount, FHeadId, FHead, Concession, payableAmount


My question is, how to get value where fee has greater than zero...

What I have tried:

.........................................................
Posted
Updated 29-Jan-17 18:49pm
Comments
Peter Leow 26-Jan-17 11:38am    
Your query looks weird, can you show the table structure and explain how a ReceiptNo relates to payments for different months.

Do you mean
SQL
... WHERE ReceiptNo='AIS/16-17/00096' GROUP BY ... HAVING SUM (Apr + May+Jun+Jul+Aug+Sep+Oct+Nov+[Dec]+Jan+Feb+Mar) > 0

But...You do realise that each clause in a GROUP BY increases teh number of separate groups generated, don't you? When you use more than one grouping field, SQL creates a group for each of the rows with distinct values in any of the named fields. And with the number of fields in your GROUP BY, I suspect you will get a separate group for each row in the input table...
 
Share this answer
 
you can try with below query


Select * from (
select ReceiptNo, S_Adm_No, paid_date, S_Adm_No, Class, S_Name, S_F_Name, Mode_Payment,ChqNo,ChqDated, bank_Name, For_the_Month ,
FHeadId, FHead,Fine, TotalAmount, Concession, payableAmount, SUM (isnull(Apr,0) + isnull(May,0) +isnull(Jun,0)+isnull(Jul,0)+isnull(Aug,0)+isnull(Sep,0)+isnull(Oct,0)+isnull(Nov,0)+isnull([Dec],0)+isnull(Jan,0)+isnull(Feb,0)+isnull(Mar,0)) as FEE
from View_Fee_Receipt_Students where ReceiptNo='AIS/16-17/00096' group by ReceiptNo,
S_Adm_No, paid_date, S_Adm_No, Class, S_Name, S_F_Name, Mode_Payment,ChqNo,ChqDated, bank_Name, For_the_Month ,
Fine, TotalAmount, FHeadId, FHead, Concession, payableAmount) as result

WHERE FEE > 0
 
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