Click to See Complete Forum and Search --> : mysql text convert to field?


luckroth
October 24th, 2007, 12:10 AM
hi all. i would like to know how i can convert text to field.
for example:

BEGIN
declare test varchar(10);
set test="id,name";
SELECT test from m_question;
END

many thank for your help.

andreasblixt
October 24th, 2007, 02:59 AM
MySQL 5 allows the following syntax:
PREPARE query FROM "SELECT id, name FROM m_question";
EXECUTE query;

The string ("SELECT id, name FROM m_question") can also be a variable (which is how you would insert "id, name" into the query.) Note that this won't work in functions or triggers (but will work in procedures.)