Results 1 to 5 of 5

Thread: Help with an Update SQL query

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Help with an Update SQL query

    Hi,

    I want to update my contacts table and set the team_id of all contacts to the team of there Parent Account. How would this be acheived with a SQL command I tried the following but that returns errors.

    But you cannot run the UPDATE statement where my selection of team_id from accounts returns mutilpe rows


    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  2. #2
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Help with an Update SQL query

    Hello,

    I guess this is the one,

    PHP Code:
    UPDATE contacts c 
    INNER JOIN accounts_contacts ac ON ac
    .contact_id c.id AND ac.deleted 
    INNER JOIN accounts a ON ac
    .account_id a.id AND a.deleted 
    SET c
    .team_id a.team_idc.team_set_id a.team_set_id AND c.deleted 0
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  3. #3
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Help with an Update SQL query

    Thanks,

    Sorry that didn't work, seems to have set all my team_id in Contacts where they have a parent Account to 0

    Warning Code : 1292
    Truncated incorrect DOUBLE value: 'a1a808dc-49a6-102c-8082-001d0911a977 '

    Any idea what this is

    #######################

    should be where c.deleted=0
    Last edited by chrislynch8; 2011-03-08 at 10:06 AM.
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  4. #4
    MissAran is offline Sugar Community Member
    Join Date
    Jul 2010
    Posts
    24

    Default Re: Help with an Update SQL query

    I believe it's your AND within the SET arguement. I took the AND out and it updated my contacts.

    UPDATE contacts c
    INNER JOIN accounts_contacts ac ON ac.contact_id = c.id AND ac.deleted = 0
    INNER JOIN accounts a ON ac.account_id = a.id AND a.deleted = 0
    SET c.team_id = a.team_id, c.team_set_id = a.team_set_id, c.deleted = 0;

    Updated version of davidboris.

    Tried and tested.

    But, the results are if the contact is deleted it will be made undeleted with that c.deleted = 0. I guess you don't want that.

    UPDATE contacts c
    INNER JOIN accounts_contacts ac ON ac.contact_id = c.id AND ac.deleted = 0
    INNER JOIN accounts a ON ac.account_id = a.id AND a.deleted = 0
    SET c.team_id = a.team_id, c.team_set_id = a.team_set_id;
    Last edited by MissAran; 2011-03-08 at 10:23 AM.

  5. #5
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Help with an Update SQL query

    Hello,

    Excuse me for the wrong query,

    PHP Code:
    UPDATE contacts c 
    INNER JOIN accounts_contacts ac ON ac
    .contact_id c.id AND ac.deleted 
    INNER JOIN accounts a ON ac
    .account_id a.id AND a.deleted 
    SET c
    .team_id a.team_idc.team_set_id a.team_set_id WHERE c.deleted 0
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. update sql query
    By vfact in forum Developer Help
    Replies: 8
    Last Post: 2010-10-14, 06:41 AM
  2. Replies: 1
    Last Post: 2010-05-07, 10:34 AM
  3. Update Query in Merge
    By DerekWait7 in forum Developer Help
    Replies: 0
    Last Post: 2009-11-18, 06:55 AM
  4. Update Query
    By kongara in forum Developer Help
    Replies: 1
    Last Post: 2007-08-08, 12:51 AM
  5. Update Query question
    By asimzaidi in forum Help
    Replies: 2
    Last Post: 2007-07-09, 05:57 AM

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
  •