Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a some data grouping by a, b, c, and d. In some condition, i want to print use reportviewer, by grouping a and c to one group and b and d to one group. Is that any way to do this?

Say field name='product_type', inside it is type a, type b, type c and type d.
Normally when do grouping, is use 'Group by product_type', so it will display all the type a in one group, type b in one group and etc.
But now what i want is, all the product under type a and type c is group in one group, and so type b and type d.
Posted
Updated 9-Jan-16 2:48am
v3
Comments
Maciej Los 9-Jan-16 7:03am    
Based on waht condition you want to group (a & b) and (c & d) into two separate groups?
BillWoodruff 9-Jan-16 8:09am    
You need to be much more specific.
Member 12115140 9-Jan-16 8:09am    
I amend my question.

There's at least two ways to achieve that, but the best option is to use proper SELECT statement, as is shown below:
SQL
DECLARE @tmp TABLE(product_type VARCHAR(5))

INSERT INTO @tmp (product_type)
VALUES('a'), ('a'), ('a'),
('b'), ('b'), ('c'),
('c'), ('c'), ('c'),
('d'), ('d'), ('d')

SELECT product_type, CASE WHEN product_type = 'c' THEN 'a'
			WHEN product_type = 'd' THEN 'b'
			ELSE product_type END AS product_type1
FROM @tmp 
ORDER BY product_type1 


Result:
product_type	product_type1
a				a
a				a
a				a
c				a
c				a
c				a
c				a
d				b
d				b
d				b
b				b
b				b


Got it?

Another way is to add formula field[^] which will do the same as SQL statement.
VB
=IIf(Fields!product_type.Value ="c", "a", IIF( Fields!product_type.Value ="d","c", Fields!product_type.Value))



To get information about grouping data in ReportViewer, please see this: Grouping Data in a ReportViewer Report[^]
 
Share this answer
 
Comments
Member 12115140 9-Jan-16 9:20am    
yes, get what you mean. Will try it
Please find below link might be helpful. generally on reportviewer there is option of grouping element you can specify there datasetName.ColumnName for more details

https://msdn.microsoft.com/en-us/library/ms251700(v=vs.80).aspx
 
Share this answer
 
Comments
Maciej Los 9-Jan-16 8:41am    
I think your answer is not related to the question... OP wants to join 4 groups into 2.
Member 12115140 9-Jan-16 8:49am    
Ya. I amend my question too. Thanks

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