Jump to content

[SOLVED] Why does "SUM" return nothing?


Moron

Recommended Posts

My first query returns the following results:

queryresults.jpg

 

The query itself is:

 

$RESULTDS=mssql_query("SELECT DV.[FY], DV.[EmpNo], DV.[NAME], DV.[EmpNo], M2.[NAMEL], M2.[NAMEF], M2.[NAMEMI], M2.[MSSNO], DV.[DATE OF SERVICE], DV.[^], DV.[sER(D-O-V-H)], DV.[CONSIDER], DV.[REIMBURSE] FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo

WHERE M2.[MSSNO] = '".$_SESSION['password']."' and DV.[FY] = '$fiscal' 

ORDER BY DV.[FY] desc");

 

But when I try to sum the Amount Spent column (the "CONSIDER" field in the database), using this:

 

$sql= "SELECT SUM(CONSIDER)  FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo
WHERE DV.[FY] = '$fiscal'" ;
$result= mssql_query($sql); 
$row = mssql_fetch_array($result); 
echo $row['total '] ; 

 

....it gives me nothing. No errors and the above results come right up, but why isn't this returning a SUM of the values in the "consider" field?

Link to comment
Share on other sites

Where is 'total' coming from? If you want SUM to be stored as 'total', you need to tell it so:

 

$sql= "SELECT SUM(CONSIDER) AS total FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo
WHERE DV.[FY] = '$fiscal'" ;
$result= mssql_query($sql); 
$row = mssql_fetch_array($result); 
echo $row['total '] ; 

Link to comment
Share on other sites

i'm going to guess that it's one of two things:  a syntax error, or the extra space in the key:

 

$sql= "SELECT SUM(CONSIDER) AS total FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo
WHERE DV.[FY] = '$fiscal'" ;
$result= mssql_query($sql) or die(mssql_error());
$row = mssql_fetch_array($result);
echo $row['total'];

Link to comment
Share on other sites

i'm going to guess that it's one of two things:  a syntax error, or the extra space in the key:

 

$sql= "SELECT SUM(CONSIDER) AS total FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo
WHERE DV.[FY] = '$fiscal'" ;
$result= mssql_query($sql) or die(mssql_error());
$row = mssql_fetch_array($result);
echo $row['total'];

 

That works! THANK YOU!!!

 

I added a piece into the "where" clause and that's perfect.

 

Thanks!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.