I am having a problem with a Crystal Report that displays data from a MySQL table. I am currently gathering the data directly from the table, however when the users try to input parameters, problems arise such as:
- null values for parameters returning errors
- parameters not working as specified
I then created a stored procedure to return data if a parameter is empty and will make the MySQL server do the work rather than the Crystal Reports server.
However Crystal Reports doesn't appear to recognize this and I am having some trouble displaying the results of the procedure.
Here is a copy of the procedure i am using:
Create Procedure sp_report
(IN @param1 varchar(64),
IN @param2 varchar(64),
IN @param3 int )
Begin
IF @param1 is null AND @param2 is null AND @param3 is null Then
Select * from tblData
ELSE IF @param1 is null AND @param2 is not null AND @param3 is not null then
Select * from tblData where field3 = @param3 and field2 = @param2
ELSE IF @param1 is not null AND @param2 is not null AND @param3 is null then
Select * from tblData where field2 = @param2 and field1 = @param1
ELSE IF @param1 is not null AND @param2 is null AND @param3 is not null then
Select * from tblData where field3 = @param3 and field1 = @param1
ELSE IF @param1 is not null AND @param2 is null AND @param3 is null then
Select * from tblData where field1 = @param1
ELSE IF @param1 is null AND @param2 is not null AND @param3 is null then
Select * from tblData where field2 = @param2
ELSE IF @param1 is null AND @param2 is null AND @param3 is not null then
Select * from tblData where field3 = @param3
ELSE IF @param1 is not null AND @param2 is not null AND @param3 is not null then
Select * from tblData where field3 = @param3 and field2 = @param2 and field1 = @param1
END;
Is there an easier way to do this or am I doing something wrong? Any suggestions would be greatly appreciated.