Problems while trying to make a query with variables in the conditions (stored procedure)

Posted by pablo89 on Stack Overflow See other posts from Stack Overflow or by pablo89
Published on 2010-06-16T16:18:13Z Indexed on 2010/06/16 16:22 UTC
Read the original article Hit count: 120

Filed under:
|
|

Hi!! Im having a problem, Im trying to do a query... I remember that in the past I did something like this but today this query is returning nothing, no error, no data, just nothing... the query is something like this:


SELECT field1, @variableX:=field2
FROM table
WHERE 
    (SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=0)>0 AND
    (SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=4)=0;

I also tried this query but it didnt work (also it gaves no error):


SELECT field1, @variableX:=field2,
@variableY:=(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=0),
@variableZ:=(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=4)
FROM table
WHERE @variableY>0 AND @variableZ=0;

As you can see, what Im trying to do in the 1st query is use a variable in the conditions; in the 2nd query Im trying to create some variables and evaluate them in the conditions. At the end in the 2nd query the @variableY=1 AND @variableZ=0 but I dont know what the query returns an empty data

What could be wrong here??? Any comment or suggest is welcome!!! thanks!!! Bye!!!

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql