Results 1 to 4 of 4

Thread: Join or IF Statement??

  1. #1
    gkeyes is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    29

    Default Join or IF Statement??

    Using Sugar 5c with Zucker Reports 1.8g

    I am working with the NOTES section and trying to figure out how to write the report code for this section.

    In order to pull the information that the note applies to you have to link in some way from the NOTES Table using the parent_type and parent_ID fields.

    Example: A NOTE is created and it references an ACCOUNT. The parent_type will be populated with the word ACCOUNT and the parent_id will be populated with the key for the matching account record.

    In my case the NOTE could reference a/an ACCOUNT, LEAD or CONTACT.

    My question is how should I write this to pull the proper information for First/last name, actual account name or the Lead Name.

    I have looked at the Join Command and cannot get that to work, although I must admit the join confuses me.

    Would IF statements work in some way? Could someone give an example of the best way to work this?

    Again if I did not make it clear, pulling the fields from NOTES is not a problem, trying to pull from THREE other tables and not knowing which it might be is my problem, so I need to query in some way I guess.

  2. #2
    gkeyes is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    29

    Default Re: Join or IF Statement??

    Any Ideas from any one?

  3. #3
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Join or IF Statement??

    an example of IF & JOIN

    Hope it helps


    select parent_type, `accounts`.`name`, if (parent_type = 'cases', 'CASE', 'NOT CASE')
    from tasks
    left join cases on tasks.parent_id = cases.id
    left JOIN accounts ON (tasks.parent_id = accounts.id OR cases.account_id = accounts.id)
    Last edited by mikesolomon; 2008-05-22 at 04:07 PM. Reason: changed sql

  4. #4
    gkeyes is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    29

    Default Re: Join or IF Statement??

    Thanks this looks like it might do it for me. I can modify this format to suit what I need to do.

    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sugar 5.0.0 / Sugar Forums 5.0.0 Extension Query Errors
    By benk in forum Installation and Upgrade Help
    Replies: 4
    Last Post: 2008-05-13, 03:44 PM
  2. Suger - MS SQL Server - Join Bug
    By jpearll in forum Installation and Upgrade Help
    Replies: 3
    Last Post: 2008-05-05, 10:08 PM
  3. Slow Queries
    By Romanzote in forum Help
    Replies: 0
    Last Post: 2007-03-07, 03:25 PM
  4. Replies: 0
    Last Post: 2006-10-28, 12:08 PM
  5. URGENT:Add join table crete_list_query
    By somaggio in forum Developer Help
    Replies: 0
    Last Post: 2006-10-27, 08:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •