Port Microsoft SQL SELECT CASE to Crystal Reports 11
I have a Microsoft SQL Query:
SELECT case
when ReHired Is Null Then HireDate
else ReHired
end CheckDate
FROM
Em开发者_StackOverflow社区ployees
This of course creates a column -- CheckDate -- using either the HireDate or Re-HiredDate.
How can I port this same functionality to Crystal Reports?
I knew before asking this that SQL Expression Fields in CR looked like and sounded like what I wanted, but I tried a few things and couldn't get it to work.
Finally, however, I managed to.. Just create a SQL Expression Field, plug in the select expression -- CASE WHEN ReHired IS NULL THEN HireDate ELSE ReHired END CheckDate --.
Then, simply reference this as {%CheckDate} within your CR formulas and expressions. Very easy, very powerful, exactly what I wanted.
Hope this helps someone else in the future.
In CR create formula named CheckDate with following content:
if isnull({Employees.ReHired})
then {Employees.HireDate}
else {Employees.ReHired}
and use that formula in report. Note that when your report has "Convert NULL values to default" option set, you need to change first line to someting similar:
if {Employees.ReHired}=<your db default value for ReHired column>
frame your "base" query as either a view on the sql server, and then allow crystal to filter it, or as a table returning parameterized stored procedure or function on the sql server and have crystal pass the parameters. In both cases including your "calculated" field in the result set
精彩评论