I'm trying to create a SELECT statement that returns all of the
columns in a table as well as another field that does not exist in the
table - the full name, generated from the fields in the DB (name
prefix, first name, middle name, last name). It is relatively simple
to simply concatenate the fields together, but to do some conditional
work it another problem.
This is all in a Stored Procedure, so I can declare a variable and
work with that if applicable...
SELECT *, FirstName + LastName as FullName FROM myTable WHERE
myTableID = 10
I would like to put in some conditional statements in there to allow
the proper number of spaces.
if (NamePrefix <> '') then
FullName = FullName + NamePrefix
if (FirstName <> '') then
if (FullName <> "") then
FullName = FullName + ' '
FullName = FullName + FirstName
What I am trying to avoid is if there is only a Last Name, I don't
want a few spaces before and after the Full Name.
I can't seem to figure out how to do this.
Also, as an aside, is the SQL FAQ page still functional? I've
misplaced the URL. Could someone tell it to me?
Thanks in advance.