We help IT Professionals succeed at work.

How do I add a column in Crystal Reports 2008?

mattkovo
mattkovo asked
on
Medium Priority
219 Views
Last Modified: 2012-05-06
I've searched but obviously not good enough.  How can I add a column to a report? I currently just have 1 big column and want to add 4 more that are displayed conditionally.
Comment
Watch Question

MIKESoftware Solutions Consultant
CERTIFIED EXPERT
Top Expert 2006

Commented:
Well, there are quite a few ways to "ADD A COLUMN" to a report.. basically...you'll need to choose it from the dataset. You can DRAG and DROP each separate column on the report. Then you can right click each field and format them conditionally.

Of course you can CREATE a formula field and then choose it in the same way that you did the other dataset fields.

I hope this helps. I you need more info, please provide some more detailed, specific info on exactly what you are trying to achieve.

Thanks
M

Author

Commented:
I'll try to explain better..

I'm looking to display a column conditionally.  That is easy....what I want to do is shift the other columns to the left if a particular column is not being displayed. I don't want to use a cross-tab report.

Example...

Col1    Col2    Col3       Col 4
Let's say I don't wan't to display Col2....so no I want the report to look like this...
Col1    Col3    Col4
NOT like thils
Col1               Col3       Col4
CERTIFIED EXPERT

Commented:
How do you specify which columns to show and hide?

Author

Commented:
I can use a parameter for that or for my case...just do an if then true statement.

I still don't know how to add a column.  Any ideas?
CERTIFIED EXPERT

Commented:
This is going to be a lot of work.
One way or another you are going to have to build each row individually using one or more formula fields.

For example you can build the row as a single string...

stringvar myrow;
If {?myParam} <>1 then myrow:= {table.field1} & "       ";
If {?myParam} <>2 then myrow:= Myrow & {table.field2} & "       ";
If {?myParam} <>3 then myrow:= Myrow & {table.field3} & "       ";
//remove final spaces
myrow := left(myrow, len(myrow)-7  ;
myrow

You would have to use a fixed width font and the number of spaces after each field would probably need to be adjusted based on the length of the field.

Author

Commented:
The fields will all be the same width.  I was looking around..what exactly is a template field?

Is it possible to setup all 4 columns and then say (starting with the left column) if {expression} then display, else display next column in its place if {expression2} is true? And so on?
MIKESoftware Solutions Consultant
CERTIFIED EXPERT
Top Expert 2006

Commented:
I would suggest doing this WITH IN THE SQL LOGIC...not in Crystal. You can basically get this all done using SQL Script.

M
MIKESoftware Solutions Consultant
CERTIFIED EXPERT
Top Expert 2006

Commented:
Then just use your Stored Proc or SQL Script in Crystal at the ADD COMMAND datasource line to "display" it in Crystal...then format as needed.....
CERTIFIED EXPERT
Commented:
A template field is not relevant here.  It is to do with standardising formatting.

There are various ways to build the row, but if you try to post data values to 'the next required' column, and you allow for more than one column to be suppressed then the complexity of the if statements will increase considerably.
You could use formula fields each of which contains logic to work out which value should be output from that particular formula field and then just place the formula fields in the detail line.
Or you could place copies of data fields on top of one another in each column and suppress the unwanted ones.
The approach I illustrated above is potentially the simplest in terms of the logic but limits what you can do with the result.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I think I'll try one of those out!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.