How to link tables as one-many in crystal report - crystal-reports

I am using
OS - Windows 7,
technology - progess 4gl.
I have two tables customer and order. I am displaying customer details along with their orders. Each customer may have more then one order. The report should be as below
CUSTOMER:-
CUMTOMER NAME ADDRESS
CUSTOMER1 XYZ
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ASD
2 ASDFGGH
3 FGHJFG /* IT SHOULD REPEAT FOR THE PARTICULAR CUTOMER */
CUSTOMER2 ABC
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ZXC
2 VNVN
3 JJLK
I Think for this we need one-many relationship between customer and order table. I have only customer and order temp-tables for doing this.Can you please tell me How to repeat the loop inside customer and how to link the tables in one-many relationship. Thanks in advance.

you should write a stored procedure and then link that SP with your report.

I don't know why you would need anything more complicated than a join.
Something like:
select * from customer, order where order.custNum = customer.custNum.
Having said that -- you might find this Progress Knowledgebase article relevant. Some versions of Crystal apparently produce SQL that might need to be adjusted:
http://knowledgebase.progress.com/articles/Article/18979

It sounds like you are just having an issue with how it is shown, I would join the table like Tom suggested order.custNum = customer.custNum
but in the Design section I would do the following:
GH1a Customer Name
GH1b Customer Information
GH2 Order Number
Det Order Information
you could also place all of the Customer Information (name, addr, etc) into a formula so that if the customer doesn't have all the data filled in it won't be shown, and won't show a blank line.

Related

How do I use the Detail Section when I have multiple Tables

I recently had to take over creating reports using CR 2013, but the introduction I got was kinda lackluster, so from time to time I run into some Problems.
Recently I had to use the detail section for the first time since I was somehow able to handle previous reports with just grouping and Subreports.
Now, what I was doing was create a report listing certain personal assets for each person in a table.
First I grouped by Organisation, then by Person and then put the field with their assets into details.
This worked fine until I was supposed to attach a subreport that should only be shown if it contains any records.
In my first attempt I attached the subreport in the report-footer and suppressed the section if the ID-Field for the main object of the Subreport was Null.
But that caused all personal assets in the detail-section to be duplicated, I guess because it reprinted the details for all records in both the table of the original, and of the subreport.
I solved this by removing the table from the main record and suppressing the subreport within itself.
But is there a solution to only print a detail section for the records of a specific table? Is there even a reason to do that? I am asking since I want to be sure I understand such concepts going forward.
Thank you in advance.
I understand that the introduce of the second table caused the repetition of details because it lead Crystal to make a cartesian product of the two tables.
Let's call the two tables like this to facilitate: TableA, TableB.
When you use only the TableA, think that Crystal do this:
select * from TableA
Then you introduce TableB, then Crystal would do this (just a mental model, I am not saying it does it really):
select * from TableA, TableB
If you understand SQL, you will notice what happens: a combination of all elements in both tables.
Then, the details section will consider each result of this combination.
Ex: TableA = {1,2}; TableB = {X,Y}; Result = {1X,1Y,2X,2Y}
In general, there are two approachs to avoid this. I don't know which one is applyable, since I don't know all the details of your case.
Let your main report know about the TableA only and the subreport know about the TableB only.
Create an extra group (surrogate, innermost). It should group by an unique value in TableA (an Id value would be great). Then you move the fields from details section to this new group footer section and suppress the details section.
There is another approach: create a link between both tables, but it is possible depending on the data, so I can't claim it will work. That would lead to Crystal to do something like:
select * from TableA, TableB where TableA.Id = Table.ReferenceToA
And it would possibly remove the repetitions.

Show the same field twice, side by side, with different values

How can I want print the same field twice with different value for each?
My Product and Shop tables are linked with product_id as the primary/foreign key.
Product
product_id
product_name
Shop
shop_id
product_id
quantity_product
When I use Expert Selection, I take all products on Shop_id 1 and Shop_id 2 (if Shop_id is in {1,2}...). Now I want to print 2 different quantity_product fields from Shop 1 and Shop 2 in the same line as my product_id. Something like:
product_name quantity_product(shop_id: 1) quantity_product(shop_id: 2)
1 10 20
I tried adding a new link in my database scheme with another Shop table, but it didn't work out.
You can set up a CrossTab in the summary section to handle any number of Shops. (So long as there's room on the report for all the shop columns)
If that doesn't work you can manually set up a summary for each Shop:
Keep in mind both of these solutions will need to be placed in a Footer section instead of the Details.

Crystal Reports Record Filtering using and

Currently I have a crystal report that only shows orders which included a "Storm Door" OR a "Sunroom Component". However I would like it to only show orders that include BOTH "Storm Door" AND "Sunroom Component" within a order. Any suggestions on how the code for this might look?
I think you have answered your own question - If you want the report to retrieve records where BOTH products were ordered, you would use an AND statement - {Categories.Description} = "Storm Doors" and {Categories.Description} = BetterView Sunroom Compnents". However, the issue with duplicate records sounds like a problem with the design of the report. You could try a few things
Look at the table joins and verify they are setup correctly; if you have a 'one to many' join setup, you may be retrieving multiple rows for each record. If you joined Customer to Orders on the Customer_ID, you would get every single order for each customer, etc.
Click Database > Select Distinct Records - Depending on how your report is configured and which fields you are displaying, this may remove the undesired duplicates.
Change your grouping order - Instead of grouping by Category (Storm door, Subroom), group by Customer and then count the number of orders or use an aggregate function to give you the information you need.

Design Database schema for billing system

I want to design a database for billing system. In one bill a customer might have purchased multiple different items ,for example fot bill Id 1 customer purchased 2 apples 3 bananas and 1 watermelon. i want to know how i can normalize this database.
This is a pretty standard, basic normalization exercise with a pretty standard solution. The usual approach is to have an orders table containing order ID, customer ID, order date &c., and an order_items table with a record for each line item on the order.

crystal reports total of values field

I'm using Crystal Reports 10 right now and I have my report almost finished. I have a group of customers and for each customer, I have multiple lines of customer information. The one thing I'm still trying to figure out though is how can I get a running total of one column's distinct values.
So, for example I have a customer Bob who has 6 different items. For each item, there is a manufacturer. It might be the same for all 6 items, it might be one for 3 of them and another for the other 3, or they might all be different. What I want is to have a field at the bottom of the group for Bob that would say:
Man1 - 3
Man2 - 1
Man3 - 2
with the manufacturer being on the left side and the number of items they make for that customer on the right side.
Is there anything in Crystal Reports that can do this right now? Or can someone give me some advice on where I would get started on a formula to do this? Thanks for any help you guys can give.
Need more information:
What kind of data structure are we talking about? How are the manufacturer and item data found? How are these related to the customer? How many manufacturers/items are typically found per customer?
If the manufacturer and items are two different fields, that might be simple (cross tab in customer group). If they are free form, that might be a problem. If there are separate fields for every manufacturer (I've see it happen), then that might be a problem.
Best scenario:
One field for manufacturer, one field for item, distinct relation to customer.
Possible solution:
Group by customer, sub-group by manufacturer, count of items.
Not best scenario:
Table for customer, separate table for each manufacturer.
Possible solution:
Main report, group by customer. Linked subreport on Manufacturer/items.
Worst scenario:
Free-text entry of manufacturer and items in a memo field.
Possible solution:
Redesign your database (grin).
If you have to, you can do this using logic tests through formulas, but if you have many manufacturers/items, it would get exhaustive.
Best answer: More information.