Hi Monika,
1. For "union all" function, the column should be equal. But in your query, T0.[U_Ref3] CarOrTruck is not equal to T0.[TrackNo] CarOrTruck
2. Getdate () function will retrieve today system date. There is no such field in ORIN table.
3. Declared location as variable. but there is there selection for this variable.
Query should be like this:
declare
@FromDate as DateTime declare @ToDate as DateTime set @FromDate = (select MAX(ta.docdate) from oinv ta where
ta.docdate <= '[%0]') set @ToDate = (select min (tb.docdate) from OINV tb where
tb.docdate >= '[%1]')
select distinct InvoiceDate,WhsCode,WhsName,CustomerName,DeliveryDate,Destination,CustomerPO,DeliveryTicket,CarorTruck,
LbsLoaded,TnsLoaded,ProductCode from (
SELECT T0.[DocDate] InvoiceDate,
T2.[WhsCode],T3.[WhsName], T0.[CardName] CustomerName, T2.[ShipDate]
DeliveryDate,
T2.[ShipToCode] Destination, T2.[BaseAtCard]
CustomerPO, T0.[DocNum] DeliveryTicket, T0.[TrackNo] CarOrTruck,
T2.[Quantity]*-1 LbsLoaded, T2.[Weight1]*-1
TnsLoaded, T2.[ItemCode] ProductCode
FROM OINV T0 INNER JOIN INV1 T2 ON
T0.DocEntry = T2.DocEntry INNER JOIN OITM T1 ON T1.ItemCode = T2.ItemCode
INNER JOIN OWHS T3 ON T2.WhsCode =
T3.WhsCode
union all
SELECT T0.[DocDate] InvoiceDate,
T2.[WhsCode],T3.[WhsName], T0.[CardName] CustomerName, T2.[ShipDate]
DeliveryDate,
T2.[ShipToCode] Destination, T2.[BaseAtCard]
CustomerPO, T0.[DocNum] DeliveryTicket, T0.[TrackNo] CarOrTruck,
T2.[Quantity]*-1 LbsLoaded, T2.[Weight1]*-1
TnsLoaded, T2.[ItemCode] ProductCode
FROM ORIN T0 INNER JOIN RIN1 T2 ON
T0.DocEntry = T2.DocEntry INNER JOIN OITM T1 ON T1.ItemCode = T2.ItemCode
INNER JOIN OWHS T3 ON T2.WhsCode =
T3.WhsCode
where t2.BaseEntry is NULL
) a
where InvoiceDate >=@FromDate and
InvoiceDate<= @ToDate
Thanks & Regards,
Nagarajan