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

Formula column question

Status
Not open for further replies.

mveino

Programmer
Jun 1, 2005
10
US
I want to make a field be a formula, but I'm having trouble... basically I want to concatenate a bunch of fields to make one string so I don't have to do it programatically.

I have an address table that separates streetname, house, apt, lot, etc... but not every house has an apt or lot, for example. So I want an "if" statement that if anything is in apt, to concat 'Apt ' + aptNum to the end of the string... but I can't figure out how to do an if statement and I can't find any good documentation.

Thanks!
 
Have a look at CASE WHEN

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
that did it... however, one more question... how do i specifiy a null case? for example:

case apt when '' then '' when null then '' else 'Apt ' + rtrim(apt) END

this doesn't work for some reason... the following formula returns a <null> value for the field, when the apt field is null:

rtrim(house) + ' ' + rtrim(streetName) + case apt WHEN '' THEN '' WHEN null then '' ELSE 'Apt ' + rtrim(apt) END
 
And this ?
rtrim(house) + ' ' + rtrim(streetName) + case apt WHEN > '' THEN 'Apt ' + rtrim(apt) ELSE '' END

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmm, that gives me an "Error validating the formula for column streetString" ...
 
Perhaps this ?
case apt when '' then '' when IS null then '' else 'Apt ' + rtrim(apt) END

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
same, error validating the formula... it doesn't seem to like the "IS" , either...

as soon as i change the apt field to just be nothing, like a space, a value is returned for my streetString field... but when it's null, the streetString field is <null>

very peculiar...
 
Figured it out... switched up the order of the case and it now works correctly using the > '' ... thanks!

rtrim(house) + ' ' + rtrim(streetName) + case WHEN apt > '' THEN 'Apt ' + apt ELSE '' END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top