SQL Stored Procedure to populate Crystal Report
I'm working on a stored procedure to populate a Crystal report. My company insists that we put the report parameters in the stored procedure instead of in Crystal...so that the SQL server (rather than the desktop)does the work of restricting the data. Is there anything I can do on the SQL side(possibly User Defined Data Type) to get Crystal to prompt me for a date WITHOUT the time? I started with this:
CREATE proc uspReportData @BeginDate datetime, @EndDate datetime
When Crstal prompts me for the parameters, I can type the date or use the calendar to pick a date, but I AM FORCED to enter a time. I know I could choose to ignore the time in the stored procedure, but the users don't want to see the time section of the parameter. Apparently SQL doesn't have a plain "date" parameter without a time.
I've also considered this:
CREATE proc uspReportData @BeginDate char(10), @EndDate char(10)
However if I do it this way, I can't seem to find a way to make sure a valid date is entered when Crystal prompts the user for the dates.
If using char(10) turns out to be the best method, is there a way I can pre-populate the Crystal prompts like this:
@BeginDate = 1st day of the current month
@EndDate = the current system date
Crystal seems to allow hard coded default values, but I can't find a way to do calculated default values.
I'm open to suggestions.
Thanks,
Mike
Apply the sql "IsDate" as a check
USE tempdb
CREATE TABLE test_dates (Col_1 varchar(15), Col_2 datetime)
GO
INSERT INTO test_dates VALUES ('abc', 'July 13, 1998')
GO
SELECT ISDATE(Col_1) AS Col_1, ISDATE(Col_2) AS Col_2
FROM test_dates
Here is the result set:
Col_1 Col_2
----------------- --------------------
0 1
SQL Stored Procedure to populate Crystal Report
I am new to addding Stored Procedures to Crystal Reports so I am not sure I will be much help, however, I ran a Crystal Report today with a date parameter in the Stored Procedure and the parameter in Crystal displayed a calendar so I could choose a date. Try changing your parameter to a datetime datatype. The calendar will allow your users to select a date and not have to remember the datetime format.