Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: IF statement using table search Post Reply Post New Topic
Author Message
billbjr
Newbie
Newbie


Joined: 19 Feb 2009
Location: United States
Online Status: Offline
Posts: 14
Quote billbjr Replybullet Topic: IF statement using table search
     Posted: 19 Feb 2009 at 5:07am
I have a list of customers (customer_tbl) that live in all different places in the U.S. I also have a list of zip codes within a 200-mile radius of my store (Zip200_tbl). I want to hold a special event at my store and send an invitation by mail, but only invite the customers who live in a 200-mile radius (i.e. have a zip code in my Zip200.tbl).
 
I want to create a formula field that identifies whether a customer is "In Area" or "Out of Area". Here's my best guess:
 
If {customer_tbl.zip} = {zip200_tbl} Then
    "In Area"
Else "Out of Area"
 
One other problem...some of the zips in my customer_tbl have a 4-digit extension, such as "25607-1234". My Zip200_tbl has the first 5 digits only. I will need to truncate the zips in my customer_tbl so they will match the zips in my Zip200_tbl.
 
HELP!
Bill
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 19 Feb 2009 at 5:40am
Hi Bill,
 
Are these the names of 2 tables you have
 
Customer_Tbl
Zip200_tbl
 
Can you let us know what fields you have in these two tables,and how are they related,I hope with customer ID ...
 
What you can do is link the customer_tbl and zip200_tbl using the common field value in both tables then in your record selection formula
 
enter
{zip200_tbl.fieldname} = value which tells customers in 200 mile radius...
 
Can you some sample post data from both the tables and expected output...
 
Cheers
Rahul 
IP IP Logged
billbjr
Newbie
Newbie


Joined: 19 Feb 2009
Location: United States
Online Status: Offline
Posts: 14
Quote billbjr Replybullet Posted: 19 Feb 2009 at 6:00am

fields in customer_tbl: ID, fname, lname, address, city, state, zip, phone

Fields in zip200_tbl: zip, state, county, distance
 
The common field in both tables is "zip"
 
I know I can link the common fields, but not sure how to set up the IF statement so that any zip codes in customer_tbl that are NOT in zip200_tbl result in "Out of Area". Here's my expected output
 
fname - lname - address - city - state - zip - mkt
bill - smith - 123 main st. - newton - NY - 44567 - In Area
sue - brown - 234 oak st. - fresno - CA - 99083 - Out of Area
 
and so on...
 
remember, some of the zips in the customer_tbl have a 4-digit extension, such as "25607-1234". My Zip200_tbl has the first 5 digits only. I will need to truncate the zips in my customer_tbl so they will match the zips in my Zip200_tbl.
Bill
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 19 Feb 2009 at 8:41am
Hi
 
below are the syntax to get first 5 characters
Crystal Syntax
 
left(left("25607-1234",instr("25607-1234","-")),5)
 
25607
 
Sql Server

select substring('25607-1234',1,5)

25607
 
you can use command object in crystal and write your sql and join your zip column from customer table to zip column from zip table remember if you make equi join you will only get matching records from both the tables....
 
So you command object query or sql query will be something like this
 
SELECT
custtbl.fname,
custtbl.lname,
custtbl.address,
custtbl.city,
custtbl.state,
custtbl.zip
FROM Customers TABLE custtbl
INNER JOIN ZIP TABLE ziptbl
ON substring('25607-1234',1,5) = ZIPTABLE.ZIPFIELD
 
you will need to replace the hard coded values with table.fieldname
I am not clear about IN Area and Out Area because if you use inner join it will reterive only matching zip codes from both the tables....
 
Cheers
Rahul
 
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum