Jump to content

Problem in WHERE Clause from SELECT Statement


newphpbees

Recommended 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

Link to comment
Share on other sites

i already resolved it 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

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.