SQL query error

Hello, 

I am trying to create this query to calculate opportunity age:

SELECT opportunities.id opportunity_id, opportunities.name opportunity_name, datediff(date(now()), date(opportunities.date_created)) opportunity_age_in_days, date(opportunities.date_created) created_at, date(opportunities.date_modified) updated_at, date(opportunities.date_closed) as closed_at
FROM opportunities

however I keep getting this error: 

Not Found

The requested URL was not found on this server.

Could you please let me know why?

Parents Reply Children
  • For my advanced report, I am also looking for the following information (apologies, I am a rookie on Advanced Reports in Sugar): 

    1. What is the SQL engine of SugarCRM? Is it MySQL, SQL Server, etc? Need to understand this in order to know what syntax I should use for functions. So far I've inferred that it is MySQL, but I just wanted to be sure.

    2. Can I perform a subquery inside a query? For example, I would like to do SELECT * FROM (SELECT * FROM opportunities), but it is not letting me. It's outputting a "Page Not Found" error when I try to save the query.

    Point 2 is very important for me to compute models for calculations. Thanks!

  • You are right, the  date_closed stores the Expected Close date that can be set by the user before the Opportunity is closed.
    The information that you are looking for is not stored by default in Sugar. If you want to store it at an Opportunity level you'll need to create a field and populate it when the Opportunity is closed. This can be done via SugarBPM, Logic Hook or workflow.   

    Retrieving that info from the activity stream will not be easy, the data column in the activities table will store the record name, id and the before and after value of the field that is audited. 

    You can have a look at what is stored in the activities table for a given Opportunity querying for that row like this: 

    SELECT * FROM activities where parent_id={opportunity_id};