Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if-then and parameterized where clause

Status
Not open for further replies.

Jeronimo

Programmer
Aug 2, 2001
12
US
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top