Skip to Content

Help With Query For Credit Value By Date Range

Hello All

I have written a query to check for all credit notes entered in SAP between a date range

It works fine, but i need to tweek it a bit and i have been unable to do so

The query is as below

SELECT T0.[DocDate],

T0.[CardName],

T0.[NumAtCard],

T0.[DocNum],

T1.[ItemCode],

T1.[Dscription],

T1.[Quantity],

T1.[PriceBefDi],

T1.[DiscPrcnt],

T1.[LineTotal],

T0.[Comments]

FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry

WHERE T0.[DocDate] > [%0] and T0.[DocDate] < [%1]

ORDER BY T0.[DocDate]

What i want to achieve is

I need the query to group by customer and show sub total for each customer

I need the query to only show credit notes that have the word GRA# in the remarks column

The reason being is people make mistakes sometime and sometimes a credit note needs to be entered to correct the error

I want the query to exclude these credit notes. All genunine returns have the word GRA# in the remarks column

Is this possible?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 10, 2013 at 04:25 PM

    Hi,

    Try:

    SELECT T0.[CardName],

    T0.DocDate,

    T0.[NumAtCard],

    T0.[DocNum],

    T1.[ItemCode],

    T1.[Dscription],

    T1.[Quantity],

    T1.[PriceBefDi],

    T1.[DiscPrcnt],

    T1.[LineTotal],

    T0.[Comments]

    FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry

    WHERE T0.[DocDate] > [%0] and T0.[DocDate] < [%1] and T0.[Comments] Like '%%GRA#%%'

    UNION ALL

    SELECT T0.[CardName],getdate(), 'Total','','','',sum(T1.[Quantity]),0,0,sum(T1.[LineTotal]),''

    FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry

    WHERE T0.[DocDate] > [%0] and T0.[DocDate] < [%1] and T0.[Comments] Like '%%GRA#%%'

    Group By T0.[CardName]

    Order By T0.[CardName], T0.[DocDate]

    Thanks,

    Gordon

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 08, 2013 at 02:11 PM

    Hi,

    Yes possible.

    Try this:

    SELECT T0.[DocDate],

    T0.[CardName],

    T0.[NumAtCard],

    T0.[DocNum],

    T1.[ItemCode],

    T1.[Dscription],

    sum(T1.[Quantity]),

    T1.[PriceBefDi],

    T1.[DiscPrcnt],

    sum(T1.[LineTotal]),

    T0.[Comments]

    FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry

    WHERE T0.[DocDate] > [%0] and T0.[DocDate] < [%1] and T0.[Comments] Like '%%GRA#%%'

    GROUP BY T0.[DocDate],

    T0.[CardName],

    T0.[NumAtCard],

    T0.[DocNum],

    T1.[ItemCode],

    T1.[Dscription],

    T1.[PriceBefDi],

    T1.[DiscPrcnt],

    T0.[Comments] ORDER BY T0.[DocDate]

    Thanks & Regards,

    Nagarajan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 09, 2013 at 12:33 AM

    Hi Nagarajan

    I tried it

    It is selecting the credit notes with the word GRA# in it

    That works perfectly

    But it doesn't group by Customer Name and i am not getting a sub total for each customer

    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.