Hello, Mauricio.

I've found something in comments at:

  http://dev.mysql.com/doc/mysql/en/Problems_with_alias.html

But I don't know if that will help you. Here it is:



"Posted by Ravi Kumar on November 10 2004 9:21am        



The above tip can be extended to have variables in column names.



For example:

The columns in table1 are cyJan,cyFeb,....,cyDec



To select the only column pertaining to current month:



t.sql contains:

set @a=left(date_format(now(),'%M'),3);

select concat('select cy',@a,' from table1',';');



Execute the following command:

mysql.exe -BN -u %uname% -p"%pwd%" -h %host% -P%port% dbname < t.sql > t1.sql



In t1.sql, we'll have the required command and this can be wrapped inside 

a shell script."





  

Mauricio Pellegrini <[EMAIL PROTECTED]> wrote:

> Hi ,

> 

> I need to do the following:

> Given a certain variable for example  @var  I want to include the

> contents of that variable as part of the name of a result column.

> 

> I'll try to explain myself a bit more with this example

> 

> 

>        Set @var = 'October_' ;

> 

>        Select 

> 

>           Tot as 'Totals'  <-- Here I would like to include the               
>                  contents

> of @var  

>        From sales              So the resulting column name would be

>                                'October_Totals'

> 

> The reason for this is because I don't know the value of @var which is

> typed by the operator at the time the query is run.

> 

> Is there a way to concatenate the contens of a variable  and a column

> alias at run time ?

> 

> thanks for your ideas

> Mauricio

> 

> 

> 

> 

> 

> 

> 



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.com




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to