LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   MySQL user defined variable (http://www.linuxquestions.org/questions/general-10/mysql-user-defined-variable-4175458198/)

waynesch 04-15-2013 10:23 AM

MySQL user defined variable
 
I am using MySQL 5.1.54 and would like to define a user variable. Have tried the following with no results.

use business
select name,c_num
from clients
where rep='@rep';

set @rep=rep
@rep=3 or @rep:=3

Does any one have any idea what I am doing incorrect?

Thank you,
wayne
schmtzway@yahoo.com

chrism01 04-15-2013 08:42 PM

This seems to cover it https://dev.mysql.com/doc/refman/5.1...statement.html
Code:

mysql> select * from tab1;
+---------+------+
| v1      | n1  |
+---------+------+
| teststr | NULL |
+---------+------+
1 row in set (0.00 sec)


mysql> set @my='teststr';
Query OK, 0 rows affected (0.00 sec)

mysql> select * from tab1 where v1=@my;
+---------+------+
| v1      | n1  |
+---------+------+
| teststr | NULL |
+---------+------+
1 row in set (0.00 sec)



All times are GMT -5. The time now is 11:20 AM.