×
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

City, State and ", "

City, State and ", "

City, State and ", "

(OP)
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

RE: City, State and ", "

Try this:

If IsNull({city}) then "" else {city} +
If IsNull({city}) and IsNull({state}) then "" else ',' +
If IsNull({state}) then "" else {state}

Ken Hamady
http://www.kenhamady.com/
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)

RE: City, State and ", "

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?

RE: City, State and ", "

Sorry, try changing the AND to OR in the second line.   You don't want the comma if EITHER is null.

Ken Hamady
http://www.kenhamady.com/
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)

RE: City, State and ", "

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

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