Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need Help With SQL Command / Division

Author  Topic 

jeff357
Starting Member

4 Posts

Posted - 2008-03-15 : 16:39:35
SELECT [Record Number], Date, Car, Miles_Start, Miles_Stop, Gallons_FillUp, Miles_Stop - Miles_Start AS Miles_Total, Miles_Total / Gallons_FillUp AS MPG
FROM Sheet1_Table
ORDER BY Date DESC, Car

Hi,
I have Visual Studio 2008 Pro / Using VB 9.0 / SQL Server Express 2005. I am making a Miles per gallon calculator for my dad. All Fields /Cells are populated in two records excepting the Miles_Total & MPG. The Miles_Total Comes out fine but... the MPG does not . Any help with this Query would be greatly appreciated!
Jeff L

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-03-15 : 17:15:42
What did you get? What are data types of those columns? Tried (Miles_Stop - Miles_Start)/Gallons_FillUp?
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-15 : 22:04:39
Your Miles_total column has no data until after the calculation, so you have to re-state the numerator for the MPG calculation as part of the formula again.

Change the MPG formula to (Miles_Stop - Miles_Start)/Gallons_FillUp as MPG

Edit..didn't notice rmaio already posted the correction.




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

jeff357
Starting Member

4 Posts

Posted - 2008-03-15 : 22:45:01

You Guy's are both right! Perfect!
Thank You Very Much!
Jeff L
Go to Top of Page
   

- Advertisement -