Crystal Reports - Using Report Data as Sql Command Parameter - crystal-reports

I'm hoping someone here might be able to help me with a Crystal Reports problem that's been bugging me on and off for days.
I have a report that is used as a picking slip for our warehouse staff to tell them which products to pack for each order that comes through our sales system.
The report contains all the products for the order and the quantities that need to be packed in the details section of the report which come from a number of joined tables.
My problem is that I have to then query the database again in order to get the total amount of items for each product on the order that have been packed across all orders throughout the warehouse.
The report datasource only returns records relating to the order on the picking slip so I need a sub query.
I've tried to use a SQL command with the following query:
SELECT ISNULL(SUM(QtyPacked), 0)
FROM tblPackingSlipLines
WHERE Status = 'Packed'
AND ProductId = '[ProductId]'
I'm stuck on passing the product id into the command as it is held in a text field on the report itself which is populated from tblProducts.ProductId (one of the joined tables).
Is it even possible to access this value from the command?
I've tried things like ProductId = '{tblProducts.ProductId}', #ProductId, ?ProductId and numerous other weird and wonderful permutations.
I can't use a parameter as that would require either user interaction; not possible as the report is auto generated by a Windows service or passing a static value in from the service.
I've also tried using a formula but that only pulls back the sum of QtyPacked for that distinct order line and not all packed orders in the DB:
SUM('{tblPickingSlipLines.QtyPacked}', '{tblProducts.ProductId}')
Any help would be greatly appreciated.

try using the sub report for this purpose.
Write your second query in sub report and pass the tblProducts.ProductId to the record selection parameter of the sub report through sub report links now your query comes in sub report as:
SELECT ISNULL(SUM(QtyPacked), 0)
FROM tblPackingSlipLines
WHERE Status = 'Packed'
AND ProductId = {pm-product ID}

Related

DSUM function in crystal reports?

I am trying to convert an old Microsoft Access report into Crystal reports. I have everything working perfectly except for this last small detail. The Access report uses a DSUM function within an if statement for one of the fields on the report.
After much searching, I've determined that CR doesn't have anything similar.
Here's basically what I'm dealing with.
I have a proposal report. In the details of the report I print the qty, description, and a couple of price fields.
The data looks like something this:
Proposalnum Partitem RolltoItem Unitprice
18611.............1.......... NULL........0.00
18611.............2......... NULL.......17225.92
18611............3............ 2............156.90
18611............4............. 2............482.05
What I need to do is when I print a specific part, I need to query through the rest of the records to find the parts that have a matching number in the rolltoitem field and add the unitprice to the part I'm printing.
So in this example when I print partitem #2, I need to add the 156.90 and the 482.05 from parts 3 and 4 to the 17225.92 so I print a total of 17864.87.
Is there any way to do this?
As far as i know, there is no such function.
But I would try this.
The general idea is: group the data by ProposalNum and use a subreport to select the "children rows" and sum the "children prices".
Details:
Create an empty group section by PartItem.
If you want to show only items where RoolToItem is null, use a suppress function for this case.
In the details section, put a subreport. The data source of the subreport would be the same of the main report.
Change subreport links to select data in subreport based on fields: PartItem in the main report = RolltoItem in the subreport.
Pass other fields to the subreport without select data: ProposalNum, PartItem, UnitPrice. I think you need to create parameters in the subreports before doing that - example: ParentProposalNum, ParentPartItem, ParentUnitPrice.
Create a new formula: ParentUnitPrice + Sum ({YourDataSource.UnitPrice})
Put the formula in the subreport footer a long with the other fields. Maybe: ParentProposalNum, ParentPartItem, formula.
It is a theoretical solution. I hope it points out to the right direction.
If you are trying to sum the Unitprice column for all items that have the same value in Rolltoitem, you could do this with a SQL Expression Field. The code would look something like this. My Where clause may need tweaked though since I'm not sure what your database structure looks like.
(
Select Sum("YourDataBaseTableName"."Unitprice")
From YourDataBaseTableName
Where "YourDataBaseTableName"."Rolltoitem" = *currentRolltoitemValue*
)
Syntax can also vary for SQL Expression Fields based upon what type of database you are using. The syntax I provided is fairly general, but should work on SQL Server.
EDIT: Adding example with explanation of how it works.
Here is one of my SQL Expression Fields from a crystal report that prints a Bill of Lading for shipped goods.
(
Select Sum("SHIPMENTS"."PALLET_COUNT")
From SHIPMENTS
Where "SHIPMENTS"."BOL_ID" = "BOL"."ID"
)
In my database the BOL table is the starting point. A single BOL can contain 1 or more SHIPMENTS, and a single SHIPMENTS can contain one or more PRODUCTS.
Top level grouping is on BOL.ID. The PALLET_COUNT is found once and only once on each SHIPMENTS. I also had a sorting requirement for the data in the details section that prevented me from using a Running Total Field.
This allows a BOL with 2 SHIPMENTS that contains a total of 3 products to look like this:
BOL.ID SHIPMENTS.ID SHIPMENTS.BOL_ID PALLET_COUNT PRODUCT.ID
1 10 1 2 XXX
1 9 1 1 YYY
1 10 1 2 ZZZ
The correct PALLET_COUNT for this BOL should be 3, since PRODUCTS XXX and ZZZ are in the same SHIPMENTS and the PALLET_COUNT is duplicated because of its relationship to the PRODUCTS.

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.

Crystal report that auto-emails to vendors in Parameter

This is a little bit of a stretch, but we're trying to convert old reports in an increasingly unstable Access Database and I have a question.
Here's what the report does in Access currently:
The user gets prompted for one of our many Suppliers in a drop down style list
Once the supplier is entered, that Suppliers list of parts will be populated
The report then pulls an email address from our system (IFS) and emails the list that has been populated to the email in our files.
We've made a SQL Query that will pull in the information that we need to replicate the report, but we're at a sort of cross-roads with how to get it to automatically go through the list of Suppliers that are in the Parameters and send off the email to them all automatically.
Would there be an easier way to do this in Crystal Reports (2011) besides automating the report and selecting all the parameters manually or in Oracle SQL Developer through maybe a WHILE LOOP?
Thanks in advance, and if you need any more information, I'll try and clarify!
This looks like a data driven report ( publication). You will run a query to retrieve the list if suppliers and their emails then run a report for each record returned by the query. Let say you have a report , which accepts a parameter SupplierID and the query returns data like this
SupplierID SupplierEmail
ID=1 email=supplierA#mail.com
ID=2 email=supplierB#mail.com
ID=3 email=supplierC#mail.com
The software will get row #1 and will use ID=1, as a parameter for Suppliers report, will export the report and will send the exported file to supplierA#mail.com. Then it will move to the next row and will use ID=2 as a parameter for the next run of the same report, export it and send it to supplierB#mail.com. The same will happen for row #3. You can check also this video, which demonstrates the proces: http://www.r-tag.com/Pages/Preview_CreateBatchJob.aspx .
Because the values for report parameters, emails etc are returned by the query this approach is known as data driven report ( publication).
Data driven publications are available in SSRS if you own SQLServer Enterprise license. There are other types of software who support them. The sample video above is from R-Tag, which could be useful too and supports SSRS, Crystal reports and SQL Ad-hoc queries. If you use Ad-hoc query you can export suppliers data to Excel without creating a special report.

How do i select records of crystal subreports dynamically

Good people of stack overflow.
I am stuck on this one.my crystal report is using a joined query
str = "SELECT invoices.voucher,
invoices.customer_name,invoice_details.item_name,
invoice_details.Amount FROM invoices
LEFT OUTER JOIN invoice_details
ON invoices.voucher =invoice_details.voucher "
The crystal report is grouped by voucher and the details are placed on detail section of group details to display item name and item amount.
It is working perfectly in design.
However at run time in VBNET when i select exactly the same query i get repeating line items. Example if the invoice items in invoice_details table were three in my report the three items will be repeated three times.
I have checked all over the internet for the same complain. No luck.
Someone suggested "suppress if duplicate" on an item with unique number such as voucher number. I did not get success.
Has someone met this difficulty and can you suggest how to resolve this?
If it can be of help to someone else...
My difficulty in duplicating line items was coming from using two tables, invoices and invoice_details when designing the crystal report.
And then using the link feature at crystal report design.
I had not realized i ought to have designed crystal report using a stored view (access query from the database). While using the stored view i did not do any linking at designing report but used grouping expert to group by invoice numbers.
So the report finally worked well after much frustration.

Crystal reports Count group by

I am very new to Crystal reports and I am working on fixing an existing report.
I am having an issue with a simple function, I am attempting to count the number of patients for each provider. I am connecting to EPIC Clarity database, if that helps. When I use the following, I am expecting to get a count of the patients (based on the number of PAT_ID, A unique field ) , grouped by the PROV_ID (also a unique field) count({PATIENT.PAT_ID},{CLARITY_SER.PROV_ID})
This results in the error: There must be a group that matches this field.
I am not sure what this error is trying to tell me. I have never used crystal reports before and I am not sure where to begin. any help is appreciated.