Skip to Content
author's profile photo Former Member
Former Member

Crystal Syntax "Like" Statment on date searches.

Post Author: smilbuta

CA Forum: Data Connectivity and SQL


I am currently developing an application using VS2005 and Crystal Reports.

I wish to pass a Crystal Syntax statement to the report that searches for like dates in a date column in a SQL 2005 Database..

The statments as follows.

crystalsyntax = "{EQ_Equipment.equipment_warranty} like '2009'"

I get returned an error saying string expected??

so i tested diferent formats, and if i use this string i get only one record returned out of a known test group of 10 records.

"{EQ_Equipment.equipment_warranty} Like DateValue('2009')"

so im unsure what im doing wrong. Any advice would be apreciated.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Apr 27, 2007 at 04:50 AM

    Post Author: Jagan

    CA Forum: Data Connectivity and SQL

    LIKE is used to compare strings. You're trying to compare a date with a string. That's why it says "string expected".

    I'm not sure what the result of DateValue('2009') is, but it's pretty certain that what you've then got is a date (warrenty) being 'liked' with a date, so both are being implicitely converted to strings first.

    What you could do is explicitely convert the warrenty date to a string in a format of your choice (don't rely on the implicit format) and then LIKE that with '2009'.

    Or change your statement to Year() = 2009 but this might result in Crystal doing the hard work instead of the database. Best would be to test that the warrenty date is in the year range, so that you can still use any index that might exist on the warrenty date column. See the help on 'in range operator'. e.g. in DateValue(<year>, 01, 01) to DateValue(<year>, 12, 31)

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.