Hi,
Heres a little test sp, I can't get it to use the @H variable in the
select , what am i doing wrong?, been messing for days now :(
The row caount always comes back as 0 , but if I just change the line
"SELECT count(*) INTO s from test where url=@'H';" to use url='tony'
for example or any other value it works as expected.
drop procedure ts;
delimiter //
CREATE PROCEDURE ts (
IN H varchar(255),
IN CheckStatus INT,
OUT Result varchar(10)
)
BEGIN
DECLARE s int DEFAULT 0;
SELECT H as N;
SELECT s AS TONY;
SELECT count(*) INTO s from test where url=@'H';
SELECT s AS TONY;
IF s 1
THEN select "OK" into Result;
ELSE select "FAIL" into Result;
END IF;
END;
//
delimiter ;
call ts('tony','1',@Result);
select @Result;
Here are the results as you can see @H is set to 'tony' before the
select count(*) and s = 0 before and after
mysqldelimiter //
mysql>
mysqlCREATE PROCEDURE ts (
-IN H varchar(255),
-IN CheckStatus INT,
-OUT Result varchar(10)
-)
- BEGIN
->
-DECLARE s int DEFAULT 0;
->
-SELECT H as N;
->
-SELECT s AS TONY;
->
->
-SELECT count(*) INTO s from test where url=@'H';
->
->
-SELECT s AS TONY;
->
-IF s 1
-THEN select "OK" into Result;
-ELSE select "FAIL" into Result;
-END IF;
- END;
- //
Query OK, 0 rows affected (0.00 sec)
mysql>
mysqldelimiter ;
mysql>
mysqlcall ts('tony','1',@Result);
+------+
| N |
+------+
| tony |
+------+
1 row in set (0.00 sec)
+------+
| TONY |
+------+
| 0 |
+------+
1 row in set (0.00 sec)
+------+
| TONY |
+------+
| 0 |
+------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysqlselect @Result;
+---------+
| @Result |
+---------+
| FAIL |
+---------+
1 row in set (0.00 sec)
The test table is
+-------+
| url |
+-------+
| tony |
| moira |
+-------+
Please let me know what I'm doing wrong .. Many thanks