Results 1 to 4 of 4

Thread: SQL Help with Custom Fields

  1. #1
    citapinc is offline Sugar Community Member
    Join Date
    Sep 2011
    Location
    Anaheim, CA
    Posts
    81

    Default SQL Help with Custom Fields

    SugarCRM CE 6.2.3

    I'm trying to figure out an SQL Statement but I'm stuck. Any help would be appreciated.

    I need an SQL statement that looks at a custom field called Move_Date_c which is defined as a Date field, finds all records where the move data is 30 days from today and the status is not "Dead" or "Converted".

    I come from the old dBase days so I'm still having a hard time understanding JOINS and stuff. Any help in writing this SQL statement would be great.

    Thanks.

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: SQL Help with Custom Fields

    Haven't tested this (also guessing the module):

    [PHP]
    select *
    from leads
    inner join leads_cstm on leads.id = leads_cstm.id_c
    where leads.status not in ('Dead','Converted')
    and date_add(cast(now() as date), INTERVAL 30 DAY) = leads_cstm.move_date_c

    [PHP]

  3. #3
    citapinc is offline Sugar Community Member
    Join Date
    Sep 2011
    Location
    Anaheim, CA
    Posts
    81

    Default Re: SQL Help with Custom Fields

    Quote Originally Posted by eggsurplus View Post
    Haven't tested this (also guessing the module):

    [PHP]
    select *
    from leads
    inner join leads_cstm on leads.id = leads_cstm.id_c
    where leads.status not in ('Dead','Converted')
    and date_add(cast(now() as date), INTERVAL 30 DAY) = leads_cstm.move_date_c

    [PHP]
    I'll give that one a try.

    I spent several hours last night working on this and this was the SQL Statement that I came up with:

    SELECT a.id_c, a.move_date_c, b.* from leads_cstm as a, leads as b where a.move_date_c = date_add(curdate(), interval 1 month) and a.id_c = b.id and find_in_set(b.status, "Dead, Converted") = 0

  4. #4
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: SQL Help with Custom Fields

    That looks fine at first glance. Good call on cur_date(). I should have used that instead.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 2012-04-06, 12:08 AM
  2. Replies: 0
    Last Post: 2010-02-06, 08:32 AM
  3. Tie Custom Module Fields to Contact Fields
    By DaneGerous in forum Developer Help
    Replies: 1
    Last Post: 2009-04-20, 03:05 PM
  4. Replies: 1
    Last Post: 2007-02-06, 09:21 PM
  5. Replies: 0
    Last Post: 2006-12-20, 11:39 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
  •