Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Selecting last records using param Post Reply Post New Topic
<< Prev  Page  of 2
Author Message
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Jan 2013 at 8:07am
assuming you cannot use a stored proc or a view as your data source (easier solution) you can write the sql as a commadn object and use that as your source
 
SELECT     TOP (20) field1, field2, Field3, datefield
FROM         table
ORDER BY datefield DESC
 
That limits your source data to the top 20 based on date sort.
once that is brought into the report you can reort those top 20 anyway you want
IP IP Logged
KevV
Senior Member
Senior Member


Joined: 19 May 2011
Online Status: Offline
Posts: 106
Quote KevV Replybullet Posted: 23 Jan 2013 at 10:33am
That is actuallly where I had started. This was a sql that I copied over. It was suppose to sort by the location field but never worked right. I tried with and without the order by in the sql and neither one worked right. The problem with doing the TOP 20 is I need to have it use the parameter I created.
 
KevV
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Jan 2013 at 11:14am
use the command and you can add a parameter in the command. It is on the right hand side of the command screen. Create the param and then insert it into the comand sql. Thsi will then change the record set returned at run time
This uses a param called "AmountToReturn"
 
SELECT     TOP ({?AmountToReturn}) field1, field2, Field3, datefield
FROM         table
ORDER BY datefield DESC
IP IP Logged
KevV
Senior Member
Senior Member


Joined: 19 May 2011
Online Status: Offline
Posts: 106
Quote KevV Replybullet Posted: 23 Jan 2013 at 12:32pm
When I add  "TOP ({?Number_Of_Records})" into the select statement I get an informix syntax error.
 
This is my Select statement:
 
select TOP ({?Number_Of_Records})a.opid,o.name,  
   a.from_location[1,8] frm,             
   a.date[9,10]||':'||a.date[11,12] ptime,
   b.to_location[1,7] to
 
KevV


Edited by KevV - 23 Jan 2013 at 12:35pm
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jan 2013 at 4:06am
I do not see any join from a to b, nor is a or b identified as the actual table name and hter is no order by.
IP IP Logged
KevV
Senior Member
Senior Member


Joined: 19 May 2011
Online Status: Offline
Posts: 106
Quote KevV Replybullet Posted: 24 Jan 2013 at 5:44am
This is the full sql statement:
 
select TOP ({?Number_Of_Records}) a.opid,o.name,a.from_load_id,  
   a.from_location[1,8] frm,             
   a.date[9,10]||':'||a.date[11,12] ptime,
   b.to_location[1,7] to                 
from audits a,audits b,operator o     
where a.date[1,10] >= '2013012108'    
   and a.date[1,10] < '2013012110'  
   and a.transaction_type = 'q'          
   and a.transaction_subtyp = 'W1'              
   and b.transaction_type = 'c'          
   and b.transaction_subtyp = 'PW'       
   and b.date > a.date                   
   and a.from_load_id = b.from_load_id             
   and a.opid = b.opid                   
   and b.opid = o.opid                   
   and a.from_location != b.to_location   
   and b.to_location[1] = 'G'
order by 6;
 
KevV
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jan 2013 at 6:05am

to trouble shoot

1. Did you create the param in the param list on the right? If not do that first and then double click on it to insert it into the sql. if not
2. replace the {?Number_Of_Records} with 20 and see if it runs OK. (my guess is it still fails). If it fails try and create that same SQL statement sql studio manager and fix it up there/ Then just copy it over to the command. But at least you know it is not the top N that is the problem.
 
Someone else better versed in SQL might see the issue and post too ...
IP IP Logged
KevV
Senior Member
Senior Member


Joined: 19 May 2011
Online Status: Offline
Posts: 106
Quote KevV Replybullet Posted: 24 Jan 2013 at 6:15am
I did create the param first and I also tried replacing with a fixed number and your right it does still fail. If I leave that out of the statement and just put it in the condition to suppress the section it works. I just cant sort it by the location.
 
KevV.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jan 2013 at 6:29am
you are adding this in at an 'add command' window, not in the select statement formula window, correct?
IP IP Logged
KevV
Senior Member
Senior Member


Joined: 19 May 2011
Online Status: Offline
Posts: 106
Quote KevV Replybullet Posted: 25 Jan 2013 at 9:01am
correct. I do not havy aything in the select statement.
 
KevV


Edited by KevV - 25 Jan 2013 at 9:01am
IP IP Logged
<< Prev  Page  of 2
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