Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
Good morning,

I have issues with Crystal report,In my crystal report i printing 200 of Customer's NetSale,so i need to put NetSale field total after Each 10 customer.for example

customer NetSale
Cust1 112
cust2 12
cust3 14
....
...
....
...
cust10 80
----------------------
total=(sum of above 10 value of netsale)
---------------------------
cust11 63
cust12 82
cust13 73
....
....
...
....
cust20 87
---------------------------
total=(sum of cust11 to cust20 NetSale value)

cust21
..
....
...

please help me ......
thanks..
Posted

1 solution

I think you will need to solve this at the data source end.

If you are using SQL statement in your report:
Unless you have some column in your database you can use to split the records in groups of ten I think you can solve this by adding a unique number to every 10 records and using this number to create a sub total in Crystal Report.

Use SQL ROW_NUMBER[^] to assign a unique number to each record.
Divide this number by 10 and use CEILING[^] to round the number up.
This should give the first 10 records number 1 and the next 10 records number 2, etc.
Now use this column to create the sub totals for every 10 records.

I have no time to test this, so I am not 100% sure it will work but give it a try.
I have tested it and it works, use the below statements.

Create and populate table:
SQL
CREATE TABLE Customer
(Name CHAR(8),
 Sale INTEGER DEFAULT 0)
 
DECLARE @counter INTEGER
SET @counter = 1
WHILE @counter <= 100
BEGIN
	INSERT INTO Customer VALUES ('CUST' + REPLICATE('0', 4-LEN(@counter)) + CONVERT(CHAR(4), @counter), ABS(CAST(CAST(NEWID() AS VARBINARY) AS INTEGER)) % 10000)

	SET @counter = @counter + 1
END


Create groups of 10 based on the Name:
SQL
SELECT CEILING(ROW_NUMBER() OVER(ORDER BY Name)/10.0) AS GroupID, Name, Sale
FROM Customer
ORDER BY Name
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900