I have two fields that I want to concatenate. Field1 contains null values and Field2 has values for every record. I want to concatenate only when both fields have values. I tried using a function with an if/else
statement but that doesn't work as the resulting concatenation will return values from field2.
def concat_fields(field1, field2):
if field1 == ""
return
else:
return field1 + field2
I know this is wrong. Any suggestions?
EDIT:
Answer
Based on your results, it looks like field1 may have a space (" ") in the field, instead of an empty string.
def concat_fields(field1, field2):
if field1.strip() == "" or field2.strip() == "":
return ""
else:
return field1 + field2
No comments:
Post a Comment