Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Multiple records, place in template individually Post Reply Post New Topic
Author Message
blackd77
Newbie
Newbie


Joined: 15 Oct 2007
Location: United States
Online Status: Offline
Posts: 7
Quote blackd77 Replybullet Topic: Multiple records, place in template individually
    Posted: 16 Oct 2007 at 9:58am
Hello. I'm new to Crystal Reports, and am sure this is an easy question. If I could be pointed in the direction of the tool or CR topic that would be great. I apologize for what I'm sure is the elementary nature of this question.

I am associating fields from a MS SQL server 2000 database into a one page CR template. Each field in the database has a one-to-one correlation to a box on the template save one. For a section on the template called "Material" I will have up to 12 fields that need to be displayed per Job Number (the primary key I'm using). I need to be able to place in the first row of boxes the first record found for the job number currently chosen in the form.

As noted, for each other field it's just a matter of selecting table fields and dragging them to a particular box, but for this one (since there are up to 12) I need some way to specify that for the first row of boxes the data needs to be the first record found (by a explicit SQL query or some other method of specifying data records), for the second row of boxes the data needs to be the second record found, and so on.

I had posed this question to a Transact-SQL group and the answer I received was that it could NOT be done with a Transact SQL query (I THINK it CAN be done with a MySQL query). It was suggested that I consult with Crystal Reports experts, which is what I'm doing.

Is this clear? Please let me know, as your assistance would be greatly appreciated. I am new to this.

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 16 Oct 2007 at 11:30am

How many lines can you put on the form?  Will the extra lines print even if there is no data?

I can think of a couple of ways to do this.  The easiest is going to be to have your query bring back multiple rows - one for each line that will print.
- Set up a group on Job Number.
- Put your 1-to-1 form data in group header and footer sections, depending on where it will appear in relation to the Material data.
- Set up your group data in the Details section.  If the rows will be the same, this is all you need to do as Crystal will take care of setting it up in rows as it reads the data.
 
I hope this will give you a start!
 
-Dell
IP IP Logged
blackd77
Newbie
Newbie


Joined: 15 Oct 2007
Location: United States
Online Status: Offline
Posts: 7
Quote blackd77 Replybullet Posted: 16 Oct 2007 at 11:54am
There are 12 lines that will print. It won't be acceptable to print more than that. This is a form that was created by a design person, and it's my job to make it work. I don't know the maximum number of fields that would be returned by a SQL query that would include all records found, but I could include a TOP 12 statement if I use a query directly.

When I first looked at this problem, I was trying to work around the form that the design person created. Since I was used to placing the results from individual queries in the boxes he created, and these boxes (for the "multiple records" query were already there, I sought to isolate the results for a series of queries and assign the results from each query into each of the boxes he created. I think what is being recommended (I'll know before too long) is to remove the boxes the design person has created, and put in its place the group noted above. If so, I'll have to figure out how to make the eventual result look like the one he created.

I'll give this a try. Thanks!
IP IP Logged
blackd77
Newbie
Newbie


Joined: 15 Oct 2007
Location: United States
Online Status: Offline
Posts: 7
Quote blackd77 Replybullet Posted: 16 Oct 2007 at 12:57pm
Set up a group on Job Number/Put your 1-to-1 form data in group header and footer sections, depending on where it will appear in relation to the Material data:
I selected Insert, Group, and selected the primary key from the table that contains the data I want to display, and chose "Original Order". I place the  1-to-1 data fields in the GH1 section.


- Set up your group data in the Details section.  If the rows will be the same, this is all you need to do as Crystal will take care of setting it up in rows as it reads the data.

Here's where it begins to go awry. (I'm reading the section on grouping in my CR "Complete Reference" book). I need to have each record that fits the bill (a certain job number that has Material Code numbers and quantitites) to display in the details section. If I drag/insert one set of field names from the Field Explorer to the details section, I get one record maximum. If I drag/insert two sets of fields names from the Field Explorer to the details section, I get two records, but they are identical, not the sequential records that result from the SQL queries.

If this is [still] the appropriate tool for my task, I'll dig further for my answer. I don't want this to become a basic tutorial on grouping...I can do that without taking up your time.

Thanks for your hints!
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 18 Oct 2007 at 6:55am

Are the fields you need from all 12 records exactly the same?  If so, put one set of fields in the details section. 

Change your group to be in either Ascending or Descending order.  This way all of the records with the same job number will be together and you'll have multiple records appear in the details - all of them with that job number.
 
To make sure that you have no more than 12 detail records, set up a running total field on some identifying field in your detail data.  Make it a count and tell it to reset when the Job Number changes.  Right-click on the detail section name on the left of your screen and select something like Format Section (I don't have Crystal available on this machine and I don't remember what the exact name is....)  By "Suppress" there will be a formula button - click on that button and put something like this (using the name of the running total that you created):
 
{#Detail Count} > 12
 
-Dell
IP IP Logged
blackd77
Newbie
Newbie


Joined: 15 Oct 2007
Location: United States
Online Status: Offline
Posts: 7
Quote blackd77 Replybullet Posted: 02 Nov 2007 at 12:53pm
Thanks for the reply.

It isn't doing what I'd like it to do, however.  To clarify the task, here is the *current* configuration of the page as provided to me by the design person. This page is configured as one large "details" section. No headers or footers were wanted. The primary key for this report is Job Number (JobN) from a table named "OpenJob" Each page of the report is devoted to one Job Number, and we have 33,000 job numbers and 33,000 pages. On the page along with the job number are dozens of design items completely filling a legal size page  (no database definitions were present when I was given the task of configuring inserting the database fields).  For each of these items (except for the records I have questions about) there is one record for each job number.

In the center of the page, there is an area devoted to inventory items (Material) used with each job. This section allows for up to 12 inventory items for each job number. This makes it different from the others. With those others I just need to locate a field from the Field Explorer, and drag that field to the appropriate design box in the form.

At the time I'm attempting to add the group, I've set up the four additional tables I'll need for this job, and added items from those tables to the form. I've also added the "Materials" table  to the Database fields in Field Explorer, but have not yet selected any fields from this table to the form, and I've not added any SQL queries (Commands) to the Database fields list.

So I then go to "Insert, Groups". I'm basically asked what field I want to sort and group this group by. I don't care about sorting, I'd prefer the records were listed in the sequence they were entered in the database, but there isn't a field for that in the table itself. I will only want records from the Materials table that correspond to the job number from the OpenJob table (for which there is one per page) and there are no joins yet specified in the "Show SQL query" menu item since I haven't added any items from the Materials table to the form itself.

Since Materials.MccNumber is one of the fields I will eventually want to add to the form, I'll choose that as the answer to the question above. I don't care about the "Keep Group Together" item since the list will not be spanning pages. I was NOT asked what other fields I want in this group.

That menu choice includes this statement: The section will be printed on any change of: MCCNumber.

NOW...this make me think this isn't what I want, but I'll let it go and see how it works.

This created a Group Field Name. As noted earlier, the design choices made prior to my getting involved in this disallow any headers/footers. The preview doesn't show this recently created header, only the design view, so I'm okay so far.

You wrote:

Are the fields you need from all 12 records exactly the same?  If so, put one set of fields in the details section.

They will each contain the same fields. But I've not been prompted for inclusion of any fields (save one) to the group. Do I choose them as a property of the "Group Name Field"? I've inserted the group name in the section Group Header #1 (which cannot print, due to the design decisions made). I can add fields to the "Materials" section of the form, but I'm right back to my initial problem...how to include the multiple records.






IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 02 Nov 2007 at 1:16pm
What do you mean by "Form".  Is it a scanned image or is it a form that is designed in your report.
 
Because of the way that Crystal works, you will  NOT BE ABLE TO DO THIS with data in just a single details section!!!!!  Linking to the materials table where there are multiple records per job means that there will be multiple detail sections per job.  Period.  There is no way around it because that is how the SQL will be generated behind the scenes.
 
For this to work in Crystal, you will have to do one of two things:
 
1.  As I suggested, create a group on the job number (you can set a group so that it prints in "original order" to get the order from the data.)  Put the parts of the form that are above the materials section in a group header.  Put the parts of the form that are below the materials section in a group footer.  Put your materials data in the details section and set a running count on the details so that you know how many records you have.  Set a suppress on the details section where the materials count > 12.  Have a set of blank group footer sections immediately below the details with suppress on the for materials count >= (section number) so that you always have the space for the twelve records, even if there aren't twelve.
 
2. Put all of your data into 3 details sections - one above the materials, one below the materials.  DO NOT include the materials table on the main report.  Create a subreport for the materials, linked to the main report on job number.  Use the same techniqes as in option 1 for making sure that you always have your twelve lines.
 
-Dell
IP IP Logged
blackd77
Newbie
Newbie


Joined: 15 Oct 2007
Location: United States
Online Status: Offline
Posts: 7
Quote blackd77 Replybullet Posted: 02 Nov 2007 at 1:23pm
Thanks. I did not want to send the design back for "redesign" unless someone who knows more than I about this product (that's you) indicated it needed to be done. 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 02 Nov 2007 at 7:39pm
I got an email from Dell to check this out, so here are my thoughts (what a question this is!)

My interpretation of the question is that there will be 12 records from the Materials database associated with each Job Number. You want the 12 records to print out from left to right on the SAME ROW. As Dell mentioned, CR is designed to print rows one after the other, not side by side. So, if my interpretation is correct, then you need to trick Crystal into doing what you want.

1. Use labels that span from left to right. You can still create length-wise group headers/footers and all that, but the detail section will print side by side.

2. If for some reason the labels gets you close, but the formatting is a bit off, then I would just put the labels in a subreport so that the main report can be formatted however you want.

Note: I'm no label expert b/c I've only worked with them a little bit, so I'm not definite that this will accomplish what you want.

3. Use a global formula in combination with a subreport. In the subreport, use concatenation to build a single Global string of all the Material codes associated with the job number. Print that string on the main report. This is going to take a bit of creativity to insert the correct number of spaces between each material code to make sure they all appear where they should, but it's not a big deal. (I cover this in my 'CR Encyclopedia' book, but its not like you need to be a genius to figure it out).

4. Go with 100% SQL to solve the problem (this is what I would recommend since I'm most familiar with SQL - if you know .NET, then do this using DataSets). Create a stored procedure that uses a cursor to loop through all the data and populate a temporary table. This table should have 12 fields for each material code. As the cursor loops through the Material table, it assigns the next material code to the corresponding material field in the temporary table. When the stored procedure is finished, return the temporary table as the output. This gives you all 12 material codes in a single record and now CR has no problem printing them in a single detail section on your pre-formatted form.

I hope that one of these ideas works for you!
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
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.031 seconds.