I have created 4 custom functions in Crystal Reports 10. These take as input a date-time value from a DB record, and determine whether that date-time falls inside the current Fiscal Year or the previous Fiscal Year.
These calculations were previously executed as stored procedures on an SQL Server but we are moving to another ticketing application (hosted at a vendor site) and do not currently have DB to do these calculations on.
Here is an example of one of these functions:
// Function name: isCloseDateWithinCurrentFY
Function (DateTimeVar closeTime)
// This replaces dbo.fn_FiscalYear
// Determine if the incident close date falls inside the current Fiscal Year
DateTimeVar startCurrentFiscalYear;
NumberVar currentMonth;
StringVar returnVal;
currentMonth := Month(CurrentDate);
If currentMonth >= 2 Then
startCurrentFiscalYear := Date(Year(CurrentDate), 2, 1)
Else
startCurrentFiscalYear := Date(Year(CurrentDate)-1, 2, 1);
If (closeTime >= startCurrentFiscalYear) Then
"T"
Else
"F";
When these calculations were on the SQL Server, they were utilized from a Crystal Report SQL command
SELECT
category,
subcategory,
close_time,
tyCount
FROM (
SELECT
category=ISNULL(UPPER(category),'*Unspecified'),
subcategory=ISNULL(UPPER(subcategory),'*Unspecified'),
tyCount=SUM(CASE WHEN dbo.fn_FiscalYear(close_time)='T' THEN 1 ELSE 0 END)
FROM
incident_tickets
GROUP BY
UPPER(category),
UPPER(subcategory)
) tickets
WHERE
tycmCount>0
ORDER BY
category,
subcategory
In my case I would like to replace the call to dbo.fn_FiscalYear
with a call to my custom function isCloseDateWithinCurrentFY
.
But is it possible to call a custom function from an SQL command?
Or is there some other way to restrict the returned records based on a calculation made on Crystal Report side?
TIA