×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

if-then and parameterized where clause

if-then and parameterized where clause

if-then and parameterized where clause

(OP)
I'm learning Crystal Reports v8, and am fixing some 55 old reports.  The reports currently offer results based on a date, but now we want to have a range as well as being able to see a result set showing those records with null dates (which would be unposted transactions).

I can do it with a straight SQL query, and thus could build a stored procedure to use the parameters (which come from another source); I don't want to have to build 55 stored procedures to handle this problem, and I would prefer to handle it within the formula builder if I can.  

I've tried setting the formula, but Crystal Reports doesn't seem to want to respect more than one set of parentheses, so my where clause ends up being too inclusive; using the if-then structure seems to knock out the where clause entirely, so ALL the data comes back for the report to weed through.

Basically I would like to be able to put a complicated where clause in the formula builder .. here's an example, and TIA.

{tblA.tType} = "S" and
{tblA.Place} = {?sys:place} and
(({?sys:jDays} < 0) and (IsNull({tblA.Posted}))) or
(({?sys:jDays} > -1) and ({tblA.Posted} in ({?sys:jDate} - {?sys:jDays}) to {?sys:jDate}))

I would like the where clause to come out as follows:  if the passed variable jDays is <0, then

WHERE
    (tblA.tType = 'S' AND
    tblA.Place = 211 AND
    tblA.Posted >= '2001-05-08' and
    tblA.Posted <= '2001-05-09')

otherwise

WHERE
    (tblA.tType = 'S' AND
    tblA.Place = 211 AND
    tblA.Posted is null)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close