There are these tables:
1. PackageQuotas
(PackageId, QuotaId,QuotaValue)
2.Packages
(PackageId, ParentPackageId,..)
I want for a specific ParentPackageID to gather all QuotaValues from PackageQuota (EXCEPT this ParentPackageId) and store the result to a variable.
//Get all packageIds under the parentPackageId
SELECT * FROM Packages WHERE ParentPackageID = 32455
//Get the quota value for a specific packageId
SELECT * FROM PackageQuotas WHERE QuotaID = @QuotaID AND PackageID =xxx
//Example with results
**Packages**
32455 NULL
32456 32455
32457 32455
32458 32455
**PackageQuotas**
32455 1801 8
32456 1801 2
32457 1801 1
32458 1801 3
Expected result is : sum = 6 (and not 14)
where 32455 is the actual parentPackageId
Do I have to use a cursor and which is the best way?