Question : SQL Problem

Hi,
I have the following code which brings a list of items from our sales data.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
SELECT    dbo.SorMaster.Customer + ' ' + dbo.ArCustomer.Name AS Customer, 
                      dbo.SorDetail.MPrice * dbo.SorDetail.MBackOrderQty / dbo.TblCurrency.SellExchangeRate AS Order_Value, dbo.SorDetail.MLineShipDate, 
                      dbo.SorDetail.SalesOrder, dbo.SorDetail.SalesOrderLine, ISNULL(dbo.SorCancelled.SalesOrder, 'OK') AS ORDOK, 
                      dbo.SorCancelled.SalesOrderLine AS EXPR2, dbo.TblCurrency.SellExchangeRate
FROM         dbo.SorDetail INNER JOIN
                      dbo.SorMaster ON dbo.SorDetail.SalesOrder = dbo.SorMaster.SalesOrder INNER JOIN
                      dbo.ArCustomer ON dbo.SorMaster.Customer = dbo.ArCustomer.Customer INNER JOIN
                      dbo.TblCurrency ON dbo.SorMaster.Currency = dbo.TblCurrency.Currency LEFT OUTER JOIN
                      dbo.SorCancelled ON dbo.SorDetail.SalesOrder = dbo.SorCancelled.SalesOrder AND 
                      dbo.SorDetail.SalesOrderLine = dbo.SorCancelled.SalesOrderLine
WHERE     (dbo.SorDetail.MLineShipDate >= CONVERT(DATETIME, '2010-01-01 00:00:00', 102)) AND (dbo.SorDetail.MLineShipDate <= CONVERT(DATETIME, 
                      '2010-02-01 00:00:00', 102))
GROUP BY dbo.SorDetail.MPrice * dbo.SorDetail.MBackOrderQty / dbo.TblCurrency.SellExchangeRate, dbo.SorMaster.OrderStatus, 
                      dbo.SorMaster.Customer + ' ' + dbo.ArCustomer.Name, dbo.SorDetail.MLineShipDate, dbo.SorDetail.SalesOrderLine, dbo.SorDetail.SalesOrder, 
                      dbo.SorDetail.MBackOrderQty, dbo.SorDetail.SalesOrder, dbo.ArCustomer.Customer, dbo.SorCancelled.SalesOrder, dbo.SorCancelled.SalesOrderLine, 
                      dbo.TblCurrency.SellExchangeRate
HAVING      (dbo.SorMaster.OrderStatus <> '9') AND (ISNULL(dbo.SorCancelled.SalesOrder, 'OK') = 'OK') AND 
                      (dbo.SorDetail.MPrice * dbo.SorDetail.MBackOrderQty / dbo.TblCurrency.SellExchangeRate > 0)
ORDER BY Sor.Master.Customer


There are two other tables which I need to link in. One is the SorCancelled table which holds the details of any cancelled line items and the SorAdditions table which has any additions. If Sales Order 100 line item 50 is cancelled it is added to the the SorCancelled table. The problem I have is if it is reinstated it is added to the SorAdditions table. I need to be able to check that the addition has been entered after the cancellation.

The SorCancelled table has the following schema

      [TrnDate] [datetime] NOT NULL ,
      [TrnTime] [decimal](8, 0) NOT NULL ,
      [SalesOrder] [char] (6)  NOT NULL ,
      [SalesOrderLine] [decimal](4, 0) NOT NULL ,
      [LineType] [char] (1)  NULL ,
      [CancelledValue] [decimal](14, 2) NULL ,
      [Reason] [char] (6)  NULL ,
      [Customer] [char] (7)  NULL ,
      [Salesperson] [char] (3)  NULL ,
      [Branch] [char] (2)  NULL ,
      [Operator] [char] (6)  NULL ,
      [DocumentType] [char] (1)  NULL ,
      [Area] [char] (2)  NULL ,
      [UserField1] [char] (1)  NULL ,
      [StockCode] [char] (30)  NULL ,
      [Description] [char] (30)  NULL ,
      [Warehouse] [char] (2)  NULL ,
      [OrderQty] [decimal](10, 3) NULL ,
      [OrderUom] [char] (3)  NULL ,
      [ProductClass] [char] (4)  NULL ,
      [TaxCode] [char] (1)  NULL ,
      [TimeStamp] [timestamp] NULL

The SorAdditions table
[TrnDate] [datetime] NOT NULL ,
      [TrnTime] [decimal](8, 0) NOT NULL ,
      [SalesOrder] [char] (6)  NOT NULL ,
      [SalesOrderLine] [decimal](4, 0) NOT NULL ,
      [LineType] [char] (1)  NULL ,
      [LineValue] [decimal](14, 2) NULL ,
      [CostValue] [decimal](14, 2) NULL ,
      [ProductClass] [char] (4)  NULL ,
      [Customer] [char] (7)  NULL ,
      [Branch] [char] (2)  NULL ,
      [DocumentType] [char] (1)  NULL ,
      [Salesperson] [char] (3)  NULL ,
      [Area] [char] (2)  NULL ,
      [TaxCode] [char] (1)  NULL ,
      [GstCode] [char] (1)  NULL ,
      [UserField1] [char] (1)  NULL ,
      [StockCode] [char] (30)  NULL ,
      [Description] [char] (30)  NULL ,
      [Warehouse] [char] (2)  NULL ,
      [OrderQty] [decimal](10, 3) NULL ,
      [OrderUom] [char] (3)  NULL ,
      [Price] [decimal](15, 5) NULL ,
      [PriceUom] [char] (3)  NULL ,
      [Discount] [decimal](14, 2) NULL ,
      [ShipQty] [decimal](10, 3) NULL ,
      [CreditReason] [char] (6)  NULL ,
      [Operator] [char] (6)  NULL ,
      [TimeStamp] [timestamp] NULL

Thanks in advance

Answer : SQL Problem

 #Is the following elseif always true if  $section is not null ?
  elsif ($section) {
not null and not eq '0'

       #What does the following line means?
      $section{$section}->{$up}++;
Increment the value indexed by $up in the hashref in the value indexed by $section in the %section hash

             #What does the following line means?
           $section{$section}->{$1}++;
Increment the value indexed by $1 in the hashref in the value indexed by $section in the %section hash
Random Solutions  
 
programming4us programming4us