Jump to content

[SOLVED] Select AS statement with multiple variables?


Recommended Posts

I need to be able to (within my query) place two variables into another variable as something else.  For example this is snippet of the query I have now:

 

$sql = "SELECT ID, FirstName, MiddleName, LastName  FROM Accounts order by ID ";

 

I have it print out a csv file with all of the information in different columns, so I would have a header with the names of my fields, and each column holds thier values.  What I need to do is put those first three variables together within the query AS Title.

 

In theory this is what I would need:

 

$sql = "SELECT ID, FirstName, MiddleName, LastName, FirstName + MiddleName + LastName AS Title  FROM Accounts order by ID ";

 

When I do something along these lines, it creates the title field in the header, but tries to mathematically add the values together obviously.  I haven't been able to find much help with the AS statement or how I might be able to do this.

 

Thank you in advance.

 

 

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

or

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws

 

... , CONCAT(FirstName,MiddleName,LastName) AS Title

// FirstNameMiddleNameLastName

or with a separator

..., CONCAT_WS('-',FirstName,MiddleName,LastName) AS Title

//FirstName-MiddleName-LastName

 

untested

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.