Jump to content

Problem in WHERE Clause from SELECT Statement

- - - - -

  • Please log in to reply
2 replies to this topic

#1
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 474 posts
Hi...

I have a SELECT Statement to get the Rate and Hours per employee.


$sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours 

FROM $ADODB_DB.employment AS em 

INNER JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID

LEFT JOIN $PAYROLL.regular_sum_hours AS r ON em.EMP_NO = r.EMP_NO

WHERE  em.EMP_ID = '$currentEmpID'";

$RsEarnings = $conn2->Execute($sql); 


  $Rate      = $RsEarnings->fields['RATE'];

  $Hours      = $RsEarnings->fields['Hours'];


  $Hours = substr($Hours, 0, 5);

  $Hours = str_replace(':', '.', $Hours);

  

  

 $Amount = $_POST["Amount"];

 

 $Amount = round(($Hours/8)* $Rate, 2); 


and Now I revised it, because I need to add OT_Hours in Hours where the STATUS = 'OffSet'.

here is the revised code:

$sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours, o.OT_Hours, o.STATUS 

FROM $ADODB_DB.employment AS em 

INNER JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID

LEFT JOIN $PAYROLL.regular_sum_hours AS r ON em.EMP_NO = r.EMP_NO

LEFT JOIN $PAYROLL.ot_data AS o ON r.EMP_NO = o.EMP_NO

WHERE  em.EMP_ID = '$currentEmpID' AND o.STATUS = 'OffSet'";

$RsEarnings = $conn2->Execute($sql); 


  $Rate      = $RsEarnings->fields['RATE'];

  $Hours      = $RsEarnings->fields['Hours'];

  $Offset = $RsEarnings->fields['OT_Hours'];


  $Hours = substr($Hours, 0, 5);

  $Hours = str_replace(':', '.', $Hours);

  

  $Hours = ($Hours + $Offset);

  

 $Amount = $_POST["Amount"];

 

 $Amount = round(($Hours/8)* $Rate, 2); 


When I run this revised code I noticed that if the employee has no data in ot_data OT_Hours where STATUS = 'OffSet' the Rate and Hours will not displayed.

I want it even the employee has no data on ot_data the Rate and Hours will still display..

I'm still find the solution for that.

Any help is highly appreciated..

Thank you

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Do you allow nulls in OT_Hours? Have you considered using nvl to return 0 instead of null?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 474 posts
I resolved this using this code:


$sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours, o.OT_Hours, o.STATUS 

FROM $ADODB_DB.employment AS em 

INNER JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID

LEFT JOIN $PAYROLL.regular_sum_hours AS r ON em.EMP_NO = r.EMP_NO

LEFT JOIN $PAYROLL.ot_data AS o ON ( r.EMP_NO = o.EMP_NO AND o.STATUS = 'OffSet' )

WHERE  em.EMP_ID = '$currentEmpID'";


Thank you




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users