Skip to Content

same cardname in diff cardtype

Dear Experts,

I was needed a query in which I can find same Cardname from two diff Cardtype ('Customers' and 'Vendors').

Any suggestion will be highly appreciated.

Regards,

Ravi

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Jul 25, 2014 at 08:03 AM

    Hi,

    Try this below query and let me know your feedback,

    select cardcode,cardname,Balance,CardType from ocrd G1

    where CardName in (select CardName from OCRD where CardName = g1.CardName and CardType = 'C')

    and CardType = 'S'

    union all

    select cardcode,cardname,Balance,CardType from ocrd G1

    where CardName in (select CardName from OCRD where CardName = g1.CardName and CardType = 'S')

    and CardType = 'C'

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 25, 2014 at 07:18 AM

    Hi Ravi

    Try This

    select cardname,COUNT(cardname) from ocrd

    group by CardName having COUNT(cardname)>1

    Regards,

    Kennedy

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 25, 2014 at 07:50 AM

    Hi!

    This might help also,

    SELECT

    T1.[CardName], T0.[CardCode] 'Supplier Code', T1.[CardCode] 'Customer Code'

    FROM OCRD T0

    INNER JOIN OCRD T1 ON T0.[CardName] = T1.[CardName]

    WHERE

    T1.[CardType] = 'C' AND

    T0.[CardType] = 'S'

    Regards,

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Just some modification on the first query.

      SELECT

      T1.[CardName], T0.[CardCode] 'Supplier Code', T0.[Balance] 'Supplier Balance',

      T1.[CardCode] 'Customer Code', T1.[Balance] 'Customer Balance', (T0.[Balance] + T1.[Balance]) 'Net'

      FROM OCRD T0

      INNER JOIN OCRD T1 ON T0.[CardName] = T1.[CardName]

      WHERE

      T1.[CardType] = 'C' AND

      T0.[CardType] = 'S'

      Regards,

  • Posted on Jul 25, 2014 at 07:51 AM

    Hi,

    Try this query:

    SELECT T0.[CardCode], T0.[CardName], T0.[CardType], T0.[Balance] FROM OCRD T0 left join ( select cardname from ocrd) t1 on t0.cardname = t1.cardname GROUP BY T0.[CardCode], T0.[CardName], T0.[CardType], T0.[Balance]

    having count(t0.cardname) >1

    Thanks & Regards,

    Nagarajan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 25, 2014 at 07:12 AM

    Hi,

    Try this query:

    SELECT T0.[CardCode], T0.[CardName], T0.[CardType] FROM OCRD T0 WHERE T0.[CardName] ='TEST'

    Thanks & Regards,

    Nagarajan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 25, 2014 at 08:53 AM

    Hi,

    For clarification:

    Is there difference in query result between me and Mr.Prasanna?

    Thanks & Regards,

    Nagarajan

    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.