In this article we will learn conditional formatting on Field in Crystal Reports. Will display salary of each employee and highlight the row if the salary is greater than 25,000 in red.
This article is the second part of my first article.
Step 1: Create a new Table Salary as in the following:
- SET ANSI_NULLS ON
-
- GO
-
- SET QUOTED_IDENTIFIER ON
-
- GO
-
- CREATE TABLE [dbo].[Salary](
-
- [EmpId] [int] NULL,
-
- [Salary] [numeric](18, 2) NULL
-
- ) ON [PRIMARY]
-
- GO
Step 2: Now open the Crystal Report, go to Field Explorer, right click and select Database expert like the following screen:
Step 3: from the database Expert select the Salary table and click on ‘>’ button and click ‘OK’ Button,
Step 4: Now we have Salary table. Go to Links tab, give a link to Employee table and Salary table on EmpId field like the following screenshot.
Step 5: Now we have salary table in Field Explorer
Just Drag and Drop Salary field in Details Section of Crystal Report,
Step 6: Now go to
Crystal Reports tab, Report and select
Section Expert,
Step 7: Go to details section and click on color tab,
Step 8: Click on the highlighted button, this will open Formula Workshop,
Step 9: Write your condition here like the following:
if {Salary.Salary} > 25000 then
crRed
else
CrSilver
(If the salary is greater then 25000 then highlight the row with red color else silver color),
That’s it! Just check the formula by pressing Alt + C for checking for errors like the following screenshot,
Step 10: S
ave the report and click on Main Report Preview,
Here we displayed employee records in red if the salary is greater than 25,000, else highlight in Silver color.
I hope you liked this article.