I have 2 tables Licenses and LicensesToComputers.License (LicID, LicenseName, NumberOfLicenses)LicenseToComputers (LCompID PK, LicID, CompID, IsActive)
If I want to get all computers for a given license, I would do something like this:select L.LicenseName, LC.CompID from Licenses Lleft join LicenseToComputers LC on LC.LicID = L.LicID
but I want to get LicenseName .... count all computers for that license that have IsActive = 1 ... count all computers for that license regardlessI have created a function fCountAll(@LicenseID)select count(*) from LicenseToComputers where LicID = @LicenseID
and I have created a function fCountActive(@LicenseID)select count(*) from LicenseToComputers where LicID = @LicenseID and IsActive = 1
Now it all works with this request:select LicenseName, fCountActive(LicID), fCountAll(LicID) from Licenses
I am afraid this is the worst and most inefficient way to achieve the result. My question is could you help me with a better way to select the data I want ?Thanks.