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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

City, State and ", "

Status
Not open for further replies.

BROWNIE56

Programmer
Dec 28, 2000
31
US
I have 2 fields
City and State

I need to be able to display them in the following ways

City,(comma)State
City (no comma)
State (no comma)

Example

Fresno, CA
Fresno
CA

I need the State to be in the same place as the city if the city is not chosed and the comma to be supressed if not needed.

Thank you
 
Try this:

If IsNull({city}) then "" else {city} +
If IsNull({city}) and IsNull({state}) then "" else ',' +
If IsNull({state}) then "" else {state} Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
It works as far as moving the state to the left if the city is not chosed, but the comma still appears. Is there anyway to suppress the comma?
 
Sorry, try changing the AND to OR in the second line. You don't want the comma if EITHER is null. Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
Though it is a matter of personal preference, I find this way of doing this type of formula easier to read, and less error prone.
If IsNull({City} then
{State}
Else If IsNull(State} then
{City}
Else {City} + ", " + {State}
Note that both methods have the identical result - if your city or state is potentially an empty string, you would have to add a test for that as well, such as
If (IsNull({City} or {City} = "") then
{State} etc Malcolm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top