I perform the SQL code below. Although computational expression is not Zero, all rows update with zero, as an additional information denominator is bigger in every cases.
UPDATE #t
SET ProportionOfvehicle = (CountOfVehicle / @TotalNumberOfPrivateVehicles)*100
WHERE LegalPersonID IS NOT NULL;
I could finally solved the problem by my self. I created a temp table which the data type for its computational fields are float like below
**CREATE TABLE #t
(
CountOfVehicle BIGINT,
LegalPersonID BIGINT,
RegionID BIGINT,
ProportionOfvehicle FLOAT,
ProportionOfAccident FLOAT,
ProportionOfPersonel FLOAT
)**
then insert into it for other fields except computational fields with code below
**INSERT INTO #t
(
CountOfVehicle,
LegalPersonID,
RegionID,
ProportionOfvehicle,
ProportionOfAccident,
ProportionOfPersonel
)
SELECT COUNT(*) AS CountOfVehicle,
LegalPersonID,
RegionID,
NULL AS ProportionOfvehicle,
NULL AS ProportionOfAccident,
NULL AS ProportionOfPersonel
FROM Bus.VehicleOwnerships
WHERE OwnershipTypeValue IN (1,2)
GROUP BY LegalPersonID,
RegionID**
and finally update the computational fields with the statement below
**UPDATE #t
SET ProportionOfvehicle = CountOfVehicle / @TotalNumberOfOrganizationVehicles
WHERE RegionID IS NOT NUL**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With