Hello All---I'm creating a small database that tracks a cyclist's daily rides. I want to use two computed columns to get the rolling MPH (MPH for time actually spent on the bike) and the elapsed MPH (MPH after factoring in time off of the bicycle). I enter the elapsed time in seconds, the rolling time in seconds, and the mileage. The computation is then simple enough: rollSpeed = mileage / (rollTime / 3600) elapsedSpeed = mileage / (elapsedTime / 3600)I include these equations in my table creation code like this: --calculated cols rollSpeed AS mileage / (rollTime / 3600), elapsedSpeed AS mileage / (elapsedTime / 3600), ...
But it doesn't work. It just assigns the value of 'mileage' to rollSpeed and elapsedSpeed. In fact, it doesn't make any difference whatsoever what value I place inside the parentheses: 3600, 3200, 50000 . . . I always get the mileage field as my speed value!. Adding the parentheses seems to kill it.If I remove the parentheses, the calculations are not what I want, but they do WORK. I'm mystified (not the first time, not the last, I'm sure). --calculated cols rollSpeed AS mileage / rollTime / 3600, elapsedSpeed AS mileage / elapsedTime / 3600, ...
This gives me real, calculated values back! What's going on?!?!?!?Here is the complete table creation code (with the parentheses)--followed by the INSERT statement I'm using to test it:CREATE TABLE Rides( --cols rideID int IDENTITY NOT NULL, event int NOT NULL DEFAULT 9, bikeUsed int NOT NULL DEFAULT 1, rideDate datetime NOT NULL, rollTime int NOT NULL, -- in seconds elapsedTime int NOT NULL, -- in seconds odometer float(32) NULL, mileage float(32) NOT NULL, location varchar( 50) NOT NULL DEFAULT 'Hometown, USA', notes varchar(1000) NULL, --calculated cols rollSpeed AS mileage / (rollTime / 3600), elapsedSpeed AS mileage / (elapsedTime / 3600), offBikeTime AS elapsedTime - rollTime, --constraints CONSTRAINT PK_rideID PRIMARY KEY( rideID ), CONSTRAINT FK_rideEvent FOREIGN KEY( event ) REFERENCES Events( eventID ), CONSTRAINT FK_bikeUsed FOREIGN KEY( bikeUsed ) REFERENCES Bicycles( bikeID ))--INSERT STATEMENTINSERT INTO Rides( rideDate, rollTime, elapsedTime, mileage) VALUES( GetDate(), 3600, 3700, 20.4 )
TIA,---earwicker[ch]Edited by - earwicker on 05/20/2003 17:28:40