Jump to content

[SOLVED] Select AS statement with multiple variables?


marketboy

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.