Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when I run this sub query
SQL
SELECT bovd.CusCode, bovd.RecQty from BookOrdVehDetail bovd INNER JOIN VehicleSalesDetail vsd ON bovd.CusCode = vsd.CusCode
WHERE (SELECT sum(cast(bovd.Qty AS int)) From  BookOrdVehDetail bovd Group By bovd.CusCode )
>
(select count(vsd.RecNo) New  FROM VehicleSalesDetail vsd Group By Vsd.CusCode )


Error This
XML
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.



Subquery 1 Result in this image and Sub QUery 2 and Result this >>>>> >>

http://postimg.org/image/8w2irf36p/[^]

http://postimg.org/image/vyt1ql4o1/[^]

http://postimg.org/image/p9miakjc1/[^]

i think there is more than one row should not come
i m confuse how this is come there.....

And what should i do for make this query sum(Qty) > Count(invoice)
Posted
Updated 18-Apr-13 18:52pm
v2

try this...
SQL
SELECT bovd.CusCode, bovd.RecQty from BookOrdVehDetail bovd INNER JOIN VehicleSalesDetail vsd ON bovd.CusCode = vsd.CusCode
WHERE (SELECT sum(cast(bovd1.Qty AS int)) From  BookOrdVehDetail bovd1 Group By bovd1.CusCode having bovd.CusCode=bovd1.CusCode)
>
(select count(vsd1.RecNo) New  FROM VehicleSalesDetail vsd1 Group By Vsd1.CusCode having vsd1.CusCode=vsd.CusCode)

Happy Coding!
:)
 
Share this answer
 
v3
Comments
saimm 19-Apr-13 1:48am    
SELECT bovd.CusCode, bovd.RecQty
from BookOrdVehDetail bovd
INNER JOIN
VehicleSalesDetail vsd
ON bovd.CusCode = vsd.CusCode
WHERE
(SELECT sum(cast(bovd1.Qty AS int)) From BookOrdVehDetail bovd1 where bovd.CusCode=bovd1.CusCode Group By bovd1.CusCode )
>
(select count(vsd.RecNo) New FROM VehicleSalesDetail vsd1 where vsd1.CusCode=vsd.CusCode Group By Vsd.CusCode )
saimm 19-Apr-13 1:48am    
Error This
Msg 147, Level 15, State 1, Line 1
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
saimm 19-Apr-13 1:50am    
o!!!!!!!!!!!!!!!!!!!!!! what should i do With this Query !!!!!!!!!!!
Aarti Meswania 19-Apr-13 1:52am    
see updated solution :)
saimm 19-Apr-13 2:10am    
update error (-;
Msg 8121, Level 16, State 1, Line 1
Column 'VehicleSalesDetail.CusCode' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.
try this querry after removing group by .......... nd do tell me the result after trying
 
Share this answer
 
Comments
saimm 19-Apr-13 1:08am    
after remove group by how possible sum?
and count too

i dont need sum(all) and count (all)


i need sum (order) group by CustomerCode...
i need count(invoice) Group By CustomerCOde....

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