I need to retrieve a piece of data and believe I need to use the Select/Where or the "IN" statement, however I'm not well versed in either and not sure of the proper syntax. I'm building a report that is currently generated via a PHP website with code forming an array. I'm hoping I can simplify the code using just the bit below.
Thanks in advance!
What I need is the 'oldest' {SalesOrderDeliveries.omdDeliveryDate} where {SalesOrderDeliveries.omdSalesOrderID} = {@JobIdTrimmed}, and {SalesOrderDeliveries.omdShippedComplete} = 0
Here is all the existing code from the PHP website. Seems like a bit much...
$soarray=array();
$sojarray=array();
foreach($newarray as $key=>$value){
foreach($newarray[$key] as $jid=>$gap){
$dod="";
$closecount=0;
$shipcompletecount=0;
$earliestdate="";
$earliestudate=0;
$linecounts=0;
$quantitycount=0;
$shipcount=0;
$dlstring="";
$soid=0;
$results = dbc(DB_ERPALIAS,"SELECT","SalesOrderJobLinks","omjJobID='$jid' ORDER BY omjJobID ASC");
$j=0;
while($row=odbc_fetch_array($results)){
$soid = trim($row['omjSalesOrderID']);
$solid=trim($row['omjSalesOrderLineID']);
$jobid=trim($row['omjJobID']);
$sojarray[$jid][$soid]['LINES'][$solid]="";
$j++;
}
$results = dbc(DB_ERPALIAS,"SELECT","SalesOrderDeliveries","omdSalesOrderID='$soid'");
while($row=odbc_fetch_array($results)){
$linecounts++;
$shipstring="";
$solid=trim($row['omdSalesOrderLineID']);
$sodlid=trim($row['omdSalesOrderDeliveryID']);
$sodldate=trim($row['omdDeliveryDate']);
$sodldate=str_replace(" 00:00:00.000","",$sodldate);
$sodldateunix=strtotime($sodldate);
$sodlquantity=$row['omdQuantityShipped'];
$quantitycount=$quantitycount+$sodlquantity;
$sodlshipcomplete = $row['omdShippedComplete'];
if($sodlshipcomplete==-1){
$shipcompletecount++;
$shipcount=$shipcount+$sodlquantity;
$tempsodlq=str_replace(".00000","",$sodlquantity);
$shipstring="(S:$tempsodlq)";
}else{
$shipstring="(NS)";
}
$sodlclosed=$row['omdClosed'];
if($sodlclosed==-1){
$closecount++;
}
$soarray[$soid]['DLINES'][$solid][$sodlid]['DATE']=$sodldate;
$soarray[$soid]['DLINES'][$solid][$sodlid]['UDATE']=$sodldateunix;
$soarray[$soid]['DLINES'][$solid][$sodlid]['QTY']=$sodlquantity;
$soarray[$soid]['DLINES'][$solid][$sodlid]['SHIPPED']=$sodlshipcomplete;
$soarray[$soid]['DLINES'][$solid][$sodlid]['CLOSE']=$sodlclosed;
$dlstring=$dlstring."[$solid:$sodlid]$sodldate$shipstring | ";
if($earliestdate==""){
if($sodlshipcomplete==0){
$earliestdate=$sodldate;
$earliestudate=$sodldateunix;
}
}else{
if($sodldateunix<$earliestudate){
if($sodlshipcomplete==0){
$earliestdate=$sodldate;
$earliestudate=$sodldateunix;
}
}
}
}
$soarray[$soid]['Stats']['DLINES']=$linecounts;
$soarray[$soid]['Stats']['DLSHIPPED']=$shipcompletecount;
$shipcount=round($shipcount);
$soarray[$soid]['Stats']['DLSHIPQTY']=intval($shipcount);
$soarray[$soid]['Stats']['DLSTRING']=$dlstring;
$tempgetoqty=$soarray[$sid]['Stats']['OQTY'];
$nogaps=0;
if($shipcount<$tempgetoqty){
$nogaps=1;
}
if($earliestdate!=""){
$dod = $earliestdate;
$soarray[$soid]['Stats']['DLEARLIEST']=$earliestdate;
$soarray[$soid]['Stats']['DLEARLIESTU']=$earliestudate;
}else{
if($nogaps==0){
$dod = "All Shipped";
$soarray[$soid]['Stats']['DLEARLIEST']="All Shipped";
}else{
$dod = "Diff. in Qty";
$soarray[$soid]['Stats']['DLEARLIEST']="Diff. in Qty";
}
$soarray[$soid]['Stats']['DLEARLIESTU']=time();
}