Re: How to export data with column names?

2011-02-13 Thread chamila gayan
you have to use 2 select for do this.
The first select generates the headerline and the second the data.

( SELECT 'FieldA','FieldB','FieldC', ... ) UNION ( SELECT `FieldA`,
`FieldB`, `FieldC`, ... INTO OUTFILE 'D:/data.csv'
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'  FROM ... ...
GROUP BY `FieldA`, `FieldB`, `FieldC`, ... );

http://lists.mysql.com/mysql/195820

another way is use shell and get a dump. then replace tab with ","

mysql -uuser_name -p  database -e "select * from your_table" > PATH/outfile.txt



~Chamila Gayan




On Mon, Feb 14, 2011 at 11:15 AM, mos  wrote:
> I want to use
>
> select * into outfile "myfile.txt" from table1;
>
> and have it export the data as tab delimited but with the column names. I
> need the column names because the import utility will use that to create the
> table in another (non-MySQL) database.
>
> As it stands, I can't get the column names to appear.
>
> Mike
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=cgcham...@gmail.com
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: udf return column name not value

2010-03-15 Thread chamila gayan
Thank you for your speedy reply.

I tried on your way. But it gives *error* as "*Dynamic SQL is not allowed in
stored function or trigger*". I'm using *MySql 5* as my sever. How can I
solve that.

thank you

On Mon, Mar 15, 2010 at 11:43 PM, Gavin Towey  wrote:

> You'll have to do something like this:
>
> SET @sql := CONCAT('select ',columnname,' into retval from user where
> ID=',id);
> PREPARE mySt FROM @sql;
> EXECUTE mySt;
>
>
>
> -Original Message-
> From: chamila gayan [mailto:cgcham...@gmail.com]
> Sent: Monday, March 15, 2010 12:58 AM
> To: mysql@lists.mysql.com
> Subject: udf return column name not value
>
> CREATE FUNCTION getcolumnvalue(id int,columnname varchar(30))
> RETURNS varchar(50) DETERMINISTIC
> READS SQL DATA
> begin
> declare retval varchar(50);
> return retval;
> end;
>
> I want get value of related column but it return column name.
> ex:- ('tom' what I want but it return 'name')
> plz tell what the wrong of this
>
> thank you
>
> This message contains confidential information and is intended only for the
> individual named.  If you are not the named addressee, you are notified that
> reviewing, disseminating, disclosing, copying or distributing this e-mail is
> strictly prohibited.  Please notify the sender immediately by e-mail if you
> have received this e-mail by mistake and delete this e-mail from your
> system. E-mail transmission cannot be guaranteed to be secure or error-free
> as information could be intercepted, corrupted, lost, destroyed, arrive late
> or incomplete, or contain viruses. The sender therefore does not accept
> liability for any loss or damage caused by viruses or errors or omissions in
> the contents of this message, which arise as a result of e-mail
> transmission. [FriendFinder Networks, Inc., 220 Humbolt court, Sunnyvale, CA
> 94089, USA, FriendFinder.com
>


udf return column name not value

2010-03-15 Thread chamila gayan
CREATE FUNCTION getcolumnvalue(id int,columnname varchar(30))
RETURNS varchar(50) DETERMINISTIC
READS SQL DATA
begin
declare retval varchar(50);
select columnname into retval from user where ID = id ;
return retval;
end;

I want get value of related column but it return column name.
ex:- ('tom' what I want but it return 'name')
plz tell what the wrong of this

thank you