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 6 2499
Dave wrote:
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
Well, you could:
SELECT CONCAT('Mr ',firstname,' ',lastname) FROM tblnames;
But that kind of defeats the purpose of a database, doesn't it? :-(
Thanks for that.
I don't think it defeats it really, it just saves me writing that logic
elsewhere, but still leaves the structure there so I can query just for
first names, or sort by last name.
"strawberry" <za*******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
>
Dave wrote:
>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
Well, you could:
SELECT CONCAT('Mr ',firstname,' ',lastname) FROM tblnames;
But that kind of defeats the purpose of a database, doesn't it? :-(
On Mon, 18 Sep 2006 14:07:22 GMT, in mailing.database.mysql "Dave"
<da***@nospam.co.uk>
<uK*******************@newsfe4-gui.ntli.netwrote:
>| 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).
--------------------------------------------------------------- jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jeff North wrote:
On Mon, 18 Sep 2006 14:07:22 GMT, in mailing.database.mysql "Dave"
<da***@nospam.co.uk>
<uK*******************@newsfe4-gui.ntli.netwrote:
| 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).
--------------------------------------------------------------- jn******@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;
strawberry wrote:
Jeff North wrote:
On Mon, 18 Sep 2006 14:07:22 GMT, in mailing.database.mysql "Dave"
<da***@nospam.co.uk>
<uK*******************@newsfe4-gui.ntli.netwrote:
>| 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).
--------------------------------------------------------------- jn******@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;
Oh, I made a typo there - but you get the idea.
On 18 Sep 2006 09:11:14 -0700, in mailing.database.mysql "strawberry"
<za*******@gmail.com>
<11*********************@m73g2000cwd.googlegroups. comwrote:
>| | Jeff North wrote: | On Mon, 18 Sep 2006 14:07:22 GMT, in mailing.database.mysql "Dave" | <da***@nospam.co.uk> | <uK*******************@newsfe4-gui.ntli.netwrote: | > | | 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). | --------------------------------------------------------------- | jn******@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;
My sentiments exactly :-)
--------------------------------------------------------------- jn******@yourpantsyahoo.com.au : Remove your pants to reply
--------------------------------------------------------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wm |
last post by:
I have a query that I expect to return 3 or 4 entries -- but I seem to be
getting only the most recent entry, repeated 4 times. What am I doing wrong
here?
$query="SELECT...
|
by: Phil Powell |
last post by:
I have a very simple mySqlQuery object that takes two parameters:
1) the string query
2) the db connection resource
I tested and was certain everything is passing correctly (the string
query...
|
by: Phil Powell |
last post by:
Here is the scope of what I need to do;
want:
enrollment_year
allowed (even if null)
all of ica
criteria:
|
by: Mike Poe |
last post by:
Hi,
Consider the following:
<?
$username = "foo";
$password = "bar";
$host = "db";
|
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the...
|
by: muelli75 |
last post by:
Hi!
Im getting insane by solving a problem ....
I try to define a function which uses a code-snippet from another file.
My base are the codes from the great book "WebDataBase-Book by H....
|
by: cover |
last post by:
I have a table with 50 fields that receive input depending on whether
that input came in from a 'shaker' form or a 'conveyor' form. Input
from the 'conveyor' form might populate 25 fields while...
|
by: clare at snyder.on.ca |
last post by:
I have a SQL query I need to design to select name and email addresses
for policies that are due and not renewed in a given time period. The
problem is, the database keeps the information for every...
|
by: funky |
last post by:
hello,
I've got a big problem ad i'm not able to resolve it. We have a server
running oracle 10g version 10.1.0. We usually use access as front end
and connect database tables for data extraction....
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |