SQL Query in VS/VB.NET 2005 (SQL Express) Returns NULL

  • Hi,ALL

    My name is Jeff and I have a puzzling problem with a very simple program.

    Groundwork... Visual Studio 2005 Pro using as a Language / Visual Basic 2005

    Winforms .net 2.0 SQL Express SP2 / SQL .mdf Database File Used.

    I am trying to build my dad a program to calculate and log his mileage on

    his 2 Cars. SQL Database Record Number (Key Indexed), DATE, Miles_Start,

    Miles_Stop, Total_Miles, Gallons_FillUp, & MPG (In a DataGrid). The Equasion

    is simple: Miles_Stop - Miles_Start = Miles_Total / Gallons_FillUp = MPG. I

    think(I know why does he... :)) everything goes fine with the miles_stop

    minus the miles_start = Miles_Total that works fine and correctly puts the

    Miles_Total in and when I change either the Miles_Stop or the Miles_Start

    the Miles_Total Changes (OK So Far) But in the SQL Query Box Running the

    Query Results in A NULL in the MPG Column! Also reflected in the built

    Program No MPG Computation. Also when Running the Query in the Query

    Builder the Query Makes another Column (MPG1) Below is What I have

    Entered in the Query Builder Box. :w00t: HELP! jrlvid@hughes.net

    Thanks in Advance... 🙂

    Jeff Link AS., B.S.

    SELECT [Record Number], Date, Car, Gallons_FillUp, Miles_Start, Miles_Stop, MPG, Miles_Stop - Miles_Start AS Miles_Total, Miles_Total / Gallons_FillUp AS MPG

    FROM Sheet1_Table

  • When you select all raw data in your table, do you have any null values in either Miles_Total or Gallons_FillUp fields? if so, remember that NULL values propagate. IOW, NULL + anything = NULL. To prevent this, look up the ISNULL function to get rid of NULL values in computations.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply