Hi!
First time here, I hope there is someone that can help me.
Due to staff reduction I have to make some changes in Crystal Report v8.0.1.0, a program I have never worked with before.
I have a problem the SQL query, it seems as if the WHERE clause in the default SQL query is always used even though it isn't visible in the "Show SQL query".
Background
===============
The database contains data we use to produce statistic reports for saw mills, number of boards, number of waste boards and so on. Now we want to add a number of dry boards to and count that for each "grouping" (by order name, shift, supplier etc)
The database contains a table "ProductionStatistics" with a field "ProductType". In Crystal I have a field called "BoardQuantity" that looks like this:
If ({ProductionStatistics.ProductType} = 6) Then
{ProductionStatistics.ActualQuantity}
Else
0
I also have a Sum field called "Sum of BoardQuantity" in the report that sums up for each group. All this works perfectly well.
We have added another product type (11 = dry boards) to the database and I want to do the same summation.
I created a field "BoardQuantityDry" like this:
If ({ProductionStatistics.ProductType} = 11) Then
{ProductionStatistics.ActualQuantity}
Else
0
And also made a summation field "Sum of BoardQuantityDry" in the report and entered them next to the "Sum of BoardQuantity" in all occurencies in the report.
When I look at the "Show SQL Query" I get this:
SELECT
ProductionStatistics.`ProductName`, ProductionStatistics.`ProductType`, ProductionStatistics.`ProductMinLength`, ProductionStatistics.`ProductMaxLength`, ProductionStatistics.`ActualQuantity`, ProductionStatistics.`ActualLength`, ProductionStatistics.`ActualArea`, ProductionStatistics.`ActualVolume`, ProductionStatistics.`ExtraId1`, ProductionStatistics.`ExtraId2`, ProductionStatistics.`FromTime`, ProductionStatistics.`ToTime`,
OrderName.`Name`,
Extra1.`Text`,
Extra2.`Text`
FROM
((`ProductionStatistics` ProductionStatistics INNER JOIN `Extra1` Extra1 ON
ProductionStatistics.`ExtraId1` = Extra1.`Id`)
INNER JOIN `Extra2` Extra2 ON
ProductionStatistics.`ExtraId2` = Extra2.`Id`)
INNER JOIN `OrderName` OrderName ON
ProductionStatistics.`OrderNameId` = OrderName.`Id`
WHERE
(ProductionStatistics.`ProductType` <= 3 OR
(ProductionStatistics.`ProductType` = 5 OR
ProductionStatistics.`ProductType` = 4 OR
ProductionStatistics.`ProductType` = 6 OR
ProductionStatistics.`ProductType` = 104 OR
ProductionStatistics.`ProductType` = 103))
The WHERE clause in this query looks a bit stupid too start with but the biggest problem is that it doesn't allow product type 11.
So I changed the where clause to this instead:
WHERE
(ProductionStatistics.`ProductType` <= 6 OR
ProductionStatistics.`ProductType` = 11 OR
ProductionStatistics.`ProductType` = 12 OR
ProductionStatistics.`ProductType` = 103 OR
ProductionStatistics.`ProductType` = 104)
I also have a record selection that looks like this:
{@ValidProductType}
where ValidProductType now looks like this:
if ({@ThisIsAProdStatReport}) then
(({ProductionStatistics.ProductType} < 7) Or
({ProductionStatistics.ProductType} = 11) Or
({ProductionStatistics.ProductType} = 12))
else
(({ProductionStatistics.ProductType} = 103) Or
({ProductionStatistics.ProductType} = 104))
(ThisIsAProdStatReport is always true in this case)
So product type 11 is now allowed both in the SQL query and in the record selection.
When previewing the report I still get zero result for the "Sum of BoardQuantityDry" field.
So I deleted the full SQL query and after that the WHERE clause disappeared so there should be no limits on the selection. I still don't get any values for product type = 11!
If I press the reset button I get the initial ugly WHERE clause. I suspect that Crystal is always using this clause AND any other WHERE clause I might add even though it isn't visible in "Show SQL query".
So, how do I change the SQL query to make my selection work?
Best regards
/Torkel
First time here, I hope there is someone that can help me.
Due to staff reduction I have to make some changes in Crystal Report v8.0.1.0, a program I have never worked with before.
I have a problem the SQL query, it seems as if the WHERE clause in the default SQL query is always used even though it isn't visible in the "Show SQL query".
Background
===============
The database contains data we use to produce statistic reports for saw mills, number of boards, number of waste boards and so on. Now we want to add a number of dry boards to and count that for each "grouping" (by order name, shift, supplier etc)
The database contains a table "ProductionStatistics" with a field "ProductType". In Crystal I have a field called "BoardQuantity" that looks like this:
If ({ProductionStatistics.ProductType} = 6) Then
{ProductionStatistics.ActualQuantity}
Else
0
I also have a Sum field called "Sum of BoardQuantity" in the report that sums up for each group. All this works perfectly well.
We have added another product type (11 = dry boards) to the database and I want to do the same summation.
I created a field "BoardQuantityDry" like this:
If ({ProductionStatistics.ProductType} = 11) Then
{ProductionStatistics.ActualQuantity}
Else
0
And also made a summation field "Sum of BoardQuantityDry" in the report and entered them next to the "Sum of BoardQuantity" in all occurencies in the report.
When I look at the "Show SQL Query" I get this:
SELECT
ProductionStatistics.`ProductName`, ProductionStatistics.`ProductType`, ProductionStatistics.`ProductMinLength`, ProductionStatistics.`ProductMaxLength`, ProductionStatistics.`ActualQuantity`, ProductionStatistics.`ActualLength`, ProductionStatistics.`ActualArea`, ProductionStatistics.`ActualVolume`, ProductionStatistics.`ExtraId1`, ProductionStatistics.`ExtraId2`, ProductionStatistics.`FromTime`, ProductionStatistics.`ToTime`,
OrderName.`Name`,
Extra1.`Text`,
Extra2.`Text`
FROM
((`ProductionStatistics` ProductionStatistics INNER JOIN `Extra1` Extra1 ON
ProductionStatistics.`ExtraId1` = Extra1.`Id`)
INNER JOIN `Extra2` Extra2 ON
ProductionStatistics.`ExtraId2` = Extra2.`Id`)
INNER JOIN `OrderName` OrderName ON
ProductionStatistics.`OrderNameId` = OrderName.`Id`
WHERE
(ProductionStatistics.`ProductType` <= 3 OR
(ProductionStatistics.`ProductType` = 5 OR
ProductionStatistics.`ProductType` = 4 OR
ProductionStatistics.`ProductType` = 6 OR
ProductionStatistics.`ProductType` = 104 OR
ProductionStatistics.`ProductType` = 103))
The WHERE clause in this query looks a bit stupid too start with but the biggest problem is that it doesn't allow product type 11.
So I changed the where clause to this instead:
WHERE
(ProductionStatistics.`ProductType` <= 6 OR
ProductionStatistics.`ProductType` = 11 OR
ProductionStatistics.`ProductType` = 12 OR
ProductionStatistics.`ProductType` = 103 OR
ProductionStatistics.`ProductType` = 104)
I also have a record selection that looks like this:
{@ValidProductType}
where ValidProductType now looks like this:
if ({@ThisIsAProdStatReport}) then
(({ProductionStatistics.ProductType} < 7) Or
({ProductionStatistics.ProductType} = 11) Or
({ProductionStatistics.ProductType} = 12))
else
(({ProductionStatistics.ProductType} = 103) Or
({ProductionStatistics.ProductType} = 104))
(ThisIsAProdStatReport is always true in this case)
So product type 11 is now allowed both in the SQL query and in the record selection.
When previewing the report I still get zero result for the "Sum of BoardQuantityDry" field.
So I deleted the full SQL query and after that the WHERE clause disappeared so there should be no limits on the selection. I still don't get any values for product type = 11!
If I press the reset button I get the initial ugly WHERE clause. I suspect that Crystal is always using this clause AND any other WHERE clause I might add even though it isn't visible in "Show SQL query".
So, how do I change the SQL query to make my selection work?
Best regards
/Torkel