|
Posted by strawberry on September 18, 2006, 12:11 pm
Please log in for more thread options
Jeff North wrote:
> On Mon, 18 Sep 2006 14:07:22 GMT, in mailing.database.mysql "Dave"
>
> >| Is it possible within the sql statement to prefix with a piece of text?
> >|
> >| For example, if i had a table with a column firstname and lastname, and a
> >| sql statemtn like
> >|
> >| select firstname,lastname from tblnames
> >|
> >| could i have the sql return something like "Mr John Smith" so it is all in
> >| one string?
> >|
> >| Thanks for any help
> >|
> >| Dave
>
> What happens if it is a female your responding to?
> I think it would be more preferable to do
> SELECT concat(firstname,' ',lastname) as FullName, Gender FROM myTable
> Then in code add the prefix according to gender (you might also want
> to add an age range so you can have Master and Miss as a salutation).
> ---------------------------------------------------------------
> jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
> ---------------------------------------------------------------
yes, exactly - although it's possible that the OP's statement was just
an example
personally, if i thought that it was going to be important to include
information like this then I'd put it in the db to begin with, and then
use CONCAT_WS (which handles null results more elegantly) like so:
SELECT CONCAT_WS(' ',title,',firstname,lastname) from tblnames;
|