• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 999
  • Last Modified:

How to use a date parameter in a SQL Query from Crystal Reports reading a Sybase Database

Hi Experts,

I'm trying to build a SQL Query from Crystal Reports with parameters. The database is Sybase. Each time i try something it gives me an empty report. My field is a datetime and I want to be able to have a particular date, like this :

iAgentPerformanceStat.Timestamp = {?Date}

That's what I tried last :
convert(char(10),iAgentPerformanceStat.Timestamp,101) = convert(char(10),{?Date},101)
//where {?Date} is a date not datetime format. Maybe that's the problem...

Can you help me?

P.S. I dont want to use the regular parameter from Crystal cause it takes too long the run the report like this (40 minutes), that's why I'm using the SQL query to help me.
0
Etdashou
Asked:
Etdashou
  • 3
  • 3
  • 2
2 Solutions
 
mlmccCommented:
Are you building the query is the database or trying to use a Crystal Command?

mlmcc
0
 
James0628Commented:
The fact that the parameter is a date instead of datetime theoretically shouldn't matter for the test that you posted, since it's converting both the field and parameter to mm/dd/yyyy strings (assuming that the 101 format is the same as in MS SQL).  I'm not familiar with Sybase, but what you posted looks like it should work.  About all that I can think of is to try to make sure that the field and parameter values are what you think they are, and are being interpreted correctly.  You could try identifying a specific datetime value that's in Timestamp, changing your parameter to datetime, using a simple test without the CONVERT's, and seeing if you can use the datetime parameter to find that specific value.  If so, then the basic test (datetime to datetime) is working.  If not, then maybe the Timestamp field isn't what you think it is.

 James
0
 
EtdashouAuthor Commented:
Hi mlmcc, I'm using the Command of Crystal to put my SQL Query.

For James, I tried a lot of different things and it seems that a simple compare give me an error as well :

iAgentPerformanceStat.Timestamp = {?Date}

and it gives me a blank report.

I tried my formula to have the last day :

(iAgentPerformanceStat.Timestamp>= CONVERT(varchar(10), DATEADD(dd, -1, GETDATE()), 101)
AND
iAgentPerformanceStat.Timestamp<CONVERT(varchar(10), GETDATE(), 101))

That formula works, gives me last day.

Hope this help, I still cannot give the date I want.
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
mlmccCommented:
How about trying

(iAgentPerformanceStat.Timestamp>= CONVERT(varchar(10), DATEADD(dd, -1, {?Date}), 101)
AND
iAgentPerformanceStat.Timestamp<CONVERT(varchar(10), {?Date}, 101))


mlmcc
0
 
EtdashouAuthor Commented:
Ok nice one mlmcc, it was almost it but you helped me fin the good one , here it is :

(iAgentPerformanceStat.Timestamp>=CONVERT(varchar(10), {?Date}, 101)
AND
iAgentPerformanceStat.Timestamp< CONVERT(varchar(10), DATEADD(dd, +1, {?Date}), 101))

*the only difference is that your query was looking at the day beofre the parameter, and mine is looking at the date of the paramater.

Hope this will help others as well
0
 
mlmccCommented:
Wasn't sure what date you were looking for.

mlmcc
0
 
James0628Commented:
Interesting.  Assuming that the 101 format in Sybase gives you the date without the time, then it seems odd that you would have to do that.  In theory, if you converted the field and the parameter to strings, as in your original post, then they should match.

 About the only thing that I can think of is if maybe time zones are coming into play somehow?  A datetime that was 02/23 12 AM in one time zone, would be 02/24 1 AM in the next time zone.  I don't really see how/why time zones would be coming into play here, but I can't think of any other reason that converting the datetime field and date parameter to mm/dd/yyyy strings wouldn't work.

 IAC, I'm glad that you found a solution.

 James
0
 
EtdashouAuthor Commented:
Both solutions are good depending of the what date you want to look at.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now