tommym121
asked on
SQL - conditionally insert space between fields
I have two fields that I would like to combine to form a name. I would like to have a space in between. There should be a between the two fields if both fields has a valid string. There should be no space before and after the combined string (Name).
How do I structure it?
How do I structure it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select ltrim(rtrim(firstname)) + ' ' + ltrim(rtrim(lastname)) from tablename
if your column datatype is varchar, char, or any other variant of these, then you can't prevent alphanumeric as well as special characters from entering the columns and they too will be considered as character strings.
if your column datatype is varchar, char, or any other variant of these, then you can't prevent alphanumeric as well as special characters from entering the columns and they too will be considered as character strings.
ASKER
sameer_goyal,
How can I get rid of non print character from a column?
How can I get rid of non print character from a column?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
You can combine them with a space in between by stating:
select column1 + ' ' + column2
from ....
If you can post some data examples of what you'd consider valid string, and what you wouldn't, there may be another way to write the condition.