Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Sub-Report/Command Object/Parameter ...Problem Post Reply Post New Topic
Author Message
Titanious
Newbie
Newbie


Joined: 20 Jun 2013
Location: United States
Online Status: Offline
Posts: 4
Quote Titanious Replybullet Topic: Sub-Report/Command Object/Parameter ...Problem
     Posted: 20 Jun 2013 at 11:31am

Hello all,

Crystal Reports version: 10.0.0.533
Data is stored in iHistorian Tables: "ihRawData"
Driver connecting Crystal to iHistorian = "iHistorian OLE DB Provider"

I currently have a Main Report with one Sub Report attached.

How the Process will work: The only parameter a user enters is a Batch_ID number.

In the Main report I have a Command Object which takes this Batch_ID in and prints out at the top of the main report these:?Batch_ID, Cycle_Start_Time, and Cycle_End_Time.

In the Sub Report I have a Command Object Which has two Parameters ?start_dtime and ?end_dtime which are linked to the Main Report's Cycle_Start_Time and Cycle_End_Time.
The Subreport i meant to take in the Main Report's Start and End Time then prints out the Min Temp and Max Temp for 5 Temperature Indicators within that ?start_dtime and ?end_dtime.

The Main Report's command object works great.

Main Report Command Object's SQL Query:
SELECT tagname, value, Min(timestamp) as Starttime, Max(timestamp) as Endtime
FROM ihRawData
WHERE tagname LIKE "*Tank_0047*"
AND Value = {?BatchID}
AND value != 0
AND timestamp BETWEEN yesterday-7 day AND today
AND intervalmilliseconds = 60000
AND samplingmode = interpolated
GROUP BY tagname, value

Here's an example of what is printed out at the top of the main report:
Batch ID: test0004        Cycle Start Time:6/17/2013 2:15:00PM
                                   Cycle End Time:  6/17/2013 3:33:00PM


VVVVVProblemVVVVV
The sub report seem's to be where the issue lies (maybe).

Sub Report Command Object's SQL Query:
SELECT  tagname, Min(value) as Mintemp, Max(value) as Maxtemp
FROM ihRawData
WHERE tagname LIKE "*Tank_0047*TI_TANK_0047_01*"
or tagname LIKE "*Tank_0047*TI_TANK_0047_02*"
or tagname LIKE "*Tank_0047*TI_TANK_0047_03*"
or tagname LIKE "*Tank_0047*TI_TANK_0047_04*"
or tagname LIKE "*Tank_0047*TI_TANK_0047_05*"
AND value != 0
AND timestamp BETWEEN {?start_dtime}  AND {?end_dtime}
AND intervalmilliseconds = 60000
GROUP BY tagname
ORDER BY tagname

Good Sub Report: The sub Reports query prints everything out perfectly if I DO NOT use the 2 parameters,i.e. replacing {?start_dtime} with "6/17/2013 03:15:00"  AND replacing {?end_dtime} with "6/17/2013 06:15:00".

Good sub Report Printout Example:(These aren't actual values, they are to give you a visual)
Tagname                                        Min Temp          Max Temp
-------                                              --------               --------
Tank_0047_TI_TANK_0047_01      21.33424234   27.55434534
Tank_0047_TI_TANK_0047_02      26.33424234   27.63424234
Tank_0047_TI_TANK_0047_03      24.33424234   27.43424234
Tank_0047_TI_TANK_0047_04      22.33424234   27.33424234
Tank_0047_TI_TANK_0047_05      23.33424234   27.53424234

Bad Sub Report: But, using the 2 Subreport parameters, it only prints out the first Temperature indicator with it's TempMin and TempMax with a timeframe between always within the last two hours. I.e. if I refreash the bad report the MinTemp and MaxTemp will change.

Bad sub Report Printout Example:(These aren't actual values, they are to give you a visual)
Tagname                                         Min Temp         Max Temp
-------                                               --------              --------
Tank_0047_TI_TANK_0047_01       21.33424234   27.55434534

   
Now, hardcoding the Timestamps in the Subreport query and getting a correct report is nice, but I need the timestamps to be based off of the Main report, and not be hardcoded.
Also, In the subreport, I have dragged the Parameters:"{?start_dtime}  AND {?end_dtime}" onto the report design view and looked at them in a print view to make sure the links to the Main Report's start/end time are both functioning.  Both parameters work and had the correct time.

Any Ideas?

I'd appreciate any *help*.

Thanks

IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 21 Jun 2013 at 12:44am
Hi

I think, it is a date format problem. Can you check what is the default date format in CR10 (Create a datetime paramer and drag in your report, it will show you what format it accepts your date). Also check what date format your database accepts.

Create a formula in crystal main report and change the format of your parameter and pass it to your sub report command object.
Thanks,
Sastry
IP IP Logged
Titanious
Newbie
Newbie


Joined: 20 Jun 2013
Location: United States
Online Status: Offline
Posts: 4
Quote Titanious Replybullet Posted: 21 Jun 2013 at 4:16am

Ok,

I did some more troubleshooting.  It is not a format issue, at least going from the Main Report to the sub report.
 
So, we know my Sub Report's Parameters are linked to the Main Report's Start/End Date/Times. 
 
I Dragged the Sub Report's Parameters onto the Sub Report itself to see if the link was working.  The correct Date/Time were displayed.  Then I copied those exact "Sub Report Date/Times" and went into the Sub Report's Command Object's SQL Query and replaced the Date/Time parameters with my copied text. 
 
Then the report works fine, with the hardcoded values, but I am back to hardcoding which I can't have.
 
This is truely an odd issue.  The Date/Times inside the Parameters work when I replace the Parameters with those Date/Time values, but when the parameters are used everything fails.
 
There is a possibility that the Date/Time format is changing when that information is passing from the sub report Parameter up to the Sub Report Command Object's SQL Query, so I am looking into setting the format in that Query (i.e. something like {?p_DateTime}, 'DD-MM-YYYY HH24:MI:SS') instead of just the {?p_DateTime}.  I know that notation is incorrect, but I am currently looking for the correct notation.
 
If anyone knows how to do that in a SQL Query, feel free to post.
 
Or let me know if anyone has any ideas at all the may be related to this issue.
 
 
 
 
IP IP Logged
Titanious
Newbie
Newbie


Joined: 20 Jun 2013
Location: United States
Online Status: Offline
Posts: 4
Quote Titanious Replybullet Posted: 21 Jun 2013 at 11:27am
***PROBLEM SOLVED***
 
When converting the ihRawData timestamp's Startdate and Enddate to strings everything works perfectly.
 
It is odd because Crystal detects the timestamp column as a Date/Time, and prints it ok, but if you try to use a Date/Time Parameter in a Sub Report based off of a Date/Time value in the main report, epic failure ensues.
 
The Fix:
I converted the Date/Times found in the main report to Strings with the "ToText" Function in a couple of formulas.
 
Then Link those Formulas to the subreport's StartDateTime & EndDateTime parameters.  The subreport's parameters have to also be strings.
 
That's it.  Of course this is a fix for the Timestamp column of ihRawData.  I don't know how ihTrend will handle it.
 
Oh and the lack of grouping conventions in the SLQ Query of the Command Object(s) doesn't seem to matter in Crystal Reports.  In fact, using normal grouping methods seem to cause errors in Crystal.
 
Cheers all.  TGIFBig%20smile
IP IP Logged
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