This topic is locked

Combine some fields

5/29/2009 2:35:16 PM
PHPRunner General questions
lewisgr author

I tried using:
concat(FirstName,' ',LastName, ' (',CompanyName,')')
but if there is no CompanyName the field doesn't show anything.
I want the field to show like this:
John Doe (My Company Name) or

Mary Jane ()
Is there something else I should be using besides concat?

G
giles 5/31/2009

Try:
concat( FirstName, ' ', LastName, ' (', if(CompanyName is null, ' ', CompanyName), ')' )
This should result in:
John Doe (Acme Pty Ltd) if there is a CompanyName

John Doe ( ) if that field is null

lewisgr author 6/4/2009

This worked as I explained but I should have said that I need the company to show up if there isn't first & last names.

Try:

concat( FirstName, ' ', LastName, ' (', if(CompanyName is null, ' ', CompanyName), ')' )
This should result in:
John Doe (Acme Pty Ltd) if there is a CompanyName

John Doe ( ) if that field is null

hfg 6/4/2009

Try a case statement
(CASE

WHEN LastName is null THEN concat('(', CompanyName, ')')

WHEN CompanyName is null THEN concat( FirstName, ' ', LastName)

ELSE concat( FirstName, ' ', LastName, ' (', CompanyName, ')' )

END) as field
if "is null" doesn't work quite right try "in ('',' ')"
case statements are great alternative to complex if statements