Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Sum of non-suppressed data Post Reply Post New Topic
<< Prev Page  of 2
Author Message
cpresk
Newbie
Newbie


Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
Quote cpresk Replybullet Posted: 27 Jan 2017 at 8:12am
I think this will actually help me a lot with speeding up future reports. For this particular chart, I don't think I need to join any tables. I am almost illiterate when it comes to SQL, but here is what I pared this down to -

SELECT If_no_products_floored_why_not__c, Max (Date__c) as 'maxDate', Store_Name__c,
FROM Call_Report_Entry__c

It's not working and I'm guessing it's a simple syntax error, but I can't figure out what it is.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 27 Jan 2017 at 8:32am
What is the error you're getting?

-Dell
IP IP Logged
cpresk
Newbie
Newbie


Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
Quote cpresk Replybullet Posted: 27 Jan 2017 at 9:30am
I'm trying to attach a picture, but can't figure out how to do it! It says 'Failed to retrieve data from the database......syntax error near 'SELECT........as 'maxDate'<<<???>>>, Store_Name_c......'
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 27 Jan 2017 at 10:24am
I see the issue now. Remove the comma after "Store_Name__c" in the Select part of the query.

-Dell
IP IP Logged
cpresk
Newbie
Newbie


Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
Quote cpresk Replybullet Posted: 30 Jan 2017 at 4:35am
GAAA!!! Now I have a new error! I'm definitely going to need to take some SQL training. Any suggestions?

Anyway, the new error says - 'Failed to retrieve data from database.
Details: 42000:[Simba][SQLEngine] (31430) Column 'datasource.If_no_products_floored_why_not_c' is neither in an aggregate function nor from the GROUP BY clause. [Database Vendor Code: 31430]

Any idea what that means?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 30 Jan 2017 at 5:26am
This one's an easy fix. When you use a summary (sum, max, etc) in a query, all of the fields that are not in a summary have to be in a Group By clause in the query. So, you'll need to change it to this:

SELECT If_no_products_floored_why_not__c, Max (Date__c) as 'maxDate', Store_Name__c
FROM Call_Report_Entry__c
GROUP BY If_no_products_floored_why_not__c, Store_Name__c

-Dell
IP IP Logged
cpresk
Newbie
Newbie


Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
Quote cpresk Replybullet Posted: 30 Jan 2017 at 9:39am
Getting closer...I was able to get the data in now, but I'm still getting all of the visits instead of just the most recent to each store. Do I need something else in the Max function to tell it to only include the most recent visit to each store?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 30 Jan 2017 at 10:39am
I'm pm-ing you my email address so that you can send me the report to take a look at. I think something is getting lost in translation here.

Thanks!

-Dell
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 31 Jan 2017 at 12:40pm
Ok, you're getting the extra details because of the differences in data in If_no_products_floored_why_not__c.

You have two options for this query, depending on whether SalesForce will allow you to join to a sub-query.

Option 1 - This is faster at the database level:

SELECT cre.If_no_products_floored_why_not__c, cre.Date__c as maxDate, cre.Store_Name__c
FROM Call_Report_Entry__c as 'cre'
inner join (
      Select Store_Name__c, Max(Date__c) as maxDate
      from Call_Report_Entry__c
      group by Store_Name__c
) as maxDates
on cre.Store_Name__c = maxDates.Store_Name__c
    and cre.Date__c = maxDates.maxDate

Option 2 - If it won't left you use the subquery in a join, try this:

SELECT cre.If_no_products_floored_why_not__c, cre.Date__c as maxDate, cre.Store_Name__c
FROM Call_Report_Entry__c as 'cre'
WHERE cre.Date__c =
(
      Select Max(Date__c) as maxDate
      from Call_Report_Entry__c as 'tmp'
      where tmp.Store_Name__c = cre.Store_Name__c
) as maxDates

-Dell
IP IP Logged
<< Prev Page  of 2
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.