Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
SQL
select sno,Branch,
(select transferbirds from  K_RT_RetailsDetails  where branch in (PN.sno)) as Totalbirds,
(select noofbirds from K_RT_WarehouseDetails where  branch in (PN.sno)) as Meatbirds,
(select noofbirds from K_RT_MasterBirdsTransferDet where  frombranch in (PN.sno)) as TransferBirds,
(select mortality from K_RT_DailyEntry where branch in (PN.sno)) as Mortality,
(select noofbirds from K_RT_BirdsTransfer where branch in (PN.sno)) as Tobranchtransferbirds
from K_RT_MasterRetailStores PN
Posted

1 solution

SQL
select sno,Branch,
(select count(transferbirds) from  K_RT_RetailsDetails  where branch in (PN.sno)) as Totalbirds,
(select count(noofbirds) from K_RT_WarehouseDetails where  branch in (PN.sno)) as Meatbirds,
(select count(noofbirds) from K_RT_MasterBirdsTransferDet where  frombranch in (PN.sno)) as TransferBirds,
(select count(mortality) from K_RT_DailyEntry where branch in (PN.sno)) as Mortality,
(select count(noofbirds) from K_RT_BirdsTransfer where branch in (PN.sno)) as Tobranchtransferbirds
from K_RT_MasterRetailStores PN



I have guess that you want count of total birds so i put count in subquery as per your requirements you can use count, sum, top 1 .

Here the logic is whenever you uses subquery , the result of subquery should have one and only one, not more then one row.

Please comment me if you want more detail.
 
Share this answer
 
Comments
Siva Hyderabad 19-Dec-13 7:49am    
thanks Bhavesh..

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