Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 pls check, this give me erroneous return...

Author  Topic 

jeeve01
Starting Member

25 Posts

Posted - 2009-07-24 : 01:52:25
DECLARE @datetoday datetime
DECLARE @datepast90 datetime
DECLARE @POOutstanding varchar(20)
set @datetoday = '2009/07/24'
set @datepast90 = '2009/04/24'
set @POOutstanding = 'POILO-00181'

SELECT
A.code,
A.name1,
A.StandardCost,
isnull(SUM(B.Qty),0) AS ENDING_INVENTORY,
isnull(SUM(B.Amount),0)AS AMOUNT,
isnull(SUM(C.REMAINQTY),0) as PENDING,
isnull(SUM(B.Qty),0) + isnull(SUM(C.REMAINQTY),0)as TOTALINVENTORY,
isnull(SUM(E.QTY),0) AS '90DAYSOFFTAKE',
isnull(SUM(E.Amount),0)AS 'SUM_AMOUNT',
isnull(SUM(E.Qty),0)/90 AS 'AVERAGE_OFFTAKE'
FROM A
left join B
on B.ITEMCODE = A.CODE
AND B.SHELFCODE LIKE '001'
left JOIN C
on C.ITEMCODE = A.code
and C.REMAINQTY <> 0
AND C.TRANSSTATE = 0
AND C.ISCANCEL = 0
AND C.docNO >= @POOutstanding
left JOIN D
ON C.DocNo = D.DocNo
AND D.POSTATUS<> 2
left join E
on A.code = E.ITEMCODE
and E.DOCDATE BETWEEN @datepast90 AND @datetoday
group by A.code,
A.name1,
A.StandardCost,
ORDER BY A.code

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-24 : 02:11:12
Hi

Here formatted code

DECLARE @datetoday DATETIME
DECLARE @datepast90 DATETIME
DECLARE @POOutstanding VARCHAR(20)

SET @datetoday = '2009/07/24'
SET @datepast90 = '2009/04/24'
SET @POOutstanding = 'POILO-00181'

SELECT A.code ,
A.name1 ,
A.StandardCost ,
ISNULL(SUM(B.Qty),0) AS ENDING_INVENTORY,
ISNULL(SUM(B.Amount),0) AS AMOUNT ,
ISNULL(SUM(C.REMAINQTY),0) AS PENDING ,
ISNULL(SUM(B.Qty),0) + ISNULL(SUM(C.REMAINQTY),0)AS TOTALINVENTORY ,
ISNULL(SUM(E.QTY),0) AS '90DAYSOFFTAKE' ,
ISNULL(SUM(E.Amount),0) AS 'SUM_AMOUNT' ,
ISNULL(SUM(E.Qty),0)/90 AS 'AVERAGE_OFFTAKE'
FROM A
LEFT JOIN B
ON B.ITEMCODE = A.CODE
AND B.SHELFCODE LIKE '001'
LEFT JOIN C
ON C.ITEMCODE = A.code
AND C.REMAINQTY <> 0
AND C.TRANSSTATE = 0
AND C.ISCANCEL = 0
AND C.docNO >= @POOutstanding
LEFT JOIN D
ON C.DocNo = D.DocNo
AND D.POSTATUS<> 2
LEFT JOIN E
ON A.code = E.ITEMCODE
AND E.DOCDATE BETWEEN @datepast90 AND @datetoday
GROUP BY A.code ,
A.name1 ,
A.StandardCost --Remove comma here.
ORDER BY A.code



-------------------------
R..
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-24 : 03:28:53
As rajdaksha posted: there is a comma to remove.

Next time please post the error message - thank you.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -