Solved

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

Posted on 2011-02-22
8
899 Views
Last Modified: 2012-05-11
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
Comment
Question by:Etdashou
  • 3
  • 3
  • 2
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 34956593
Are you building the query is the database or trying to use a Crystal Command?

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
ID: 34959630
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
 
LVL 1

Author Comment

by:Etdashou
ID: 34961305
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
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 34961813
How about trying

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


mlmcc
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Assisted Solution

by:Etdashou
Etdashou earned 0 total points
ID: 34962957
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 34963282
Wasn't sure what date you were looking for.

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
ID: 34968507
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
 
LVL 1

Author Closing Comment

by:Etdashou
ID: 34995431
Both solutions are good depending of the what date you want to look at.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now