Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, here in sql am subtracting the values of a two column and dispalying the resultant in another column. i am using subquery for subtraction under a condition and am getting error: sub query returns more than two values.

please help me with query .

SQL
Select Distinct spare_list.code, spare_list.Name,indentitems.qty "Quantity", (Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number) as 'On Hand', ABS((Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number)-(select indentitems.qty from indentitems left join indent on indentitems.code=indent.itemcode where indentitems.indent=16 and indent.status=1)) as "Quantity Required"from (spare_list left join SparesQty on SparesQty.Code = spare_list.Number) Left join (indentitems left join indent on indentitems.code=indent.itemcode) on spare_list.code = indentitems.code where  indentitems.indent=16 and indent.status=1 Group by spare_list.Code order by spare_list.Code
Posted
Updated 13-Jan-12 0:24am
v2

Subquery must return a single value otherwise you will get error.

put your code here.
 
Share this answer
 
Comments
devbtl 13-Jan-12 6:19am    
put your code in improve question block.
Vivek Shankar 13-Jan-12 6:20am    
Select Distinct spare_list.code, spare_list.Name,indentitems.qty "Quantity", (Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number) as 'On Hand', ABS((Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number)-(select indentitems.qty from indentitems left join indent on indentitems.code=indent.itemcode where indentitems.indent=16 and indent.status=1)) as "Quantity Required"from (spare_list left join SparesQty on SparesQty.Code = spare_list.Number) Left join (indentitems left join indent on indentitems.code=indent.itemcode) on spare_list.code = indentitems.code where indentitems.indent=16 and indent.status=1 Group by spare_list.Code order by spare_list.Code
Just try to run your sub queries one by one individually and check which one is returning more than one value and why.there must be something wrong in the condition or duplicate data:
((Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number)

(select indentitems.qty from indentitems left join indent on indentitems.code=indent.itemcode where indentitems.indent=16 and indent.status=1))
 
Share this answer
 
v2

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