Skip to Content
author's profile photo Former Member
Former Member

Purchase Query through Control Account - Correction

Dear Experts,

Can anybody help me to correct the below query, where I need to incorporate the Control Account (OINV-Ctlaccount) as one another selection parameter in the existing one.

Try this :-

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

DECLARE

@StartDate DATETIME,
@EndDate DATETIME,
@Dummy INTEGER

SELECT TOP 1 @Dummy = DocNum
FROM OPCH T0
WHERE T0.DocDate >= [%1]
AND T0.DocDate <= [%2]

SELECT

@StartDate= '[%1]'
,
@EndDate = '[%2]'

SELECT DISTINCT
T0.DocEntry,
T0.DocNum AS 'A/P Inv Num',
CONVERT(VARCHAR(10), T0.DocDate, 3) AS 'Bill Date',
T0.CardName AS 'Supplier Name',
-- T1.Dscription AS 'Item Description',
----T1.Quantity,
--T1.Price AS 'Price',
--T1.TaxCode,
SUM(T1.LineTotal) AS 'Asscessable Value',
MAX(T1.TaxCode),
--t1.vatsum as 'TaxAmount',
T0.TOTALEXPNS AS [Freight Amount],
(SUM(T1.LineTotal)+SUM(T1.VATSUM)+T0.TOTALEXPNS+T0.rounddif) as [TotAmt],
(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN (11,-90)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'BED',

(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN( -60,12)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'Cess',


(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN (-55,13)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'HeCess',

(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN (5)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'Service',

(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN (6)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'Cess_ST',

(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN (-10)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'HSCess_ST',

(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType IN (1,15)
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'VAT',

(SELECT DISTINCT ISNULL (SUM(PCH4.TaxSum),0)
FROM PCH4
WHERE PCH4.StaType = 4
AND PCH4.DocEntry = T0.DocEntry
-- AND PCH4.LineNum = T1.LineNum
) AS 'CST',
T0.Comments
--,ISNULL(T10.WTCODE,0) AS [WTCODE],ISNULL(T10.RATE,0) AS [RATE],ISNULL(T10.WTAMNT,0) AS [WTAMNT]
FROM OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN PCH5 T10 ON T0.DOCENTRY = T10.ABSENTRY
LEFT JOIN OACT T99 ON T99.ACCTCODE = T1.ACCTCODE
WHERE T0.DocDate >= @StartDate
AND T0.DocDate <= @EndDate
AND T1.TargetType < > 19
--AND T0.DOCENTRY = 8679
AND (T99.ACCTname = '[%3]' OR '[%3]' = '')
GROUP BY T0.DOCENTRY,T0.DOCNUM,T0.DOCDATE,T0.CARDNAME,T0.TOTALEXPNS,T0.ROUNDDIF,T0.COMMENTS

FOR BROWSE

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in Advance,

Bhoopathi.K

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on May 13, 2014 at 08:29 AM

    Hi,

    1. If run above query, getting error message.

    2. Already above query is added account name from OACT. Why you need from OPCH table?

    Thanks & Regards,

    Nagarajan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 13, 2014 at 08:00 AM

    Hi Bhoopati,

    Please correct me if am wrong.

    You want to include OINV.Ctlaccount or OPCH.Ctlaccount

    As this query is for Purchase Invoice.

    --

    --

    Regards::::

    Atul Chakraborty

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.