LinuxQuestions.org

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

waynesch 04-15-2013 09: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 07: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 01:26 PM.