0

I have following procured in my MySql database, which works fine for first three queries. But userId filter is not working, It should return entries with the matched UserId, but it is returning me all the records in that table. This is happening for both queries(Query of details and detailstwo table).

DELIMITER $$

DROP PROCEDURE IF EXISTS `sale`.`detailsProcedure` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `detailsProcedure`(IN userId VARCHAR(100))
BEGIN
  SELECT * FROM products WHERE ProductType=1 AND Price<=400;
  SELECT * FROM products WHERE ProductType=1 AND Price<=700;
  SELECT * FROM products WHERE ProductType=2;
  SELECT * FROM products WHERE ProductType=3;
  SELECT * FROM details WHERE UserId=userId;
  SELECT * FROM detailsTwo WHERE UserId=userId;
END $$

DELIMITER 

;

Seems like UserId is not getting compared or no filtration effect. Is there anything wrong with syntax. I looked into several post but didn't find particular solution which will help me,tried several way from stack overflow it self but problem persist.looking for help. Note:- I am calling this procedure in my node.js restapi

Thanks In Advance!

1
  • Have you tried UserId=@userId Also, maybe rename your input variable different, like v_userId to make sure it's not confused Commented Sep 27, 2017 at 20:28

1 Answer 1

1

Try this one:

DELIMITER $$

DROP PROCEDURE IF EXISTS `sale`.`detailsProcedure` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `detailsProcedure`(IN v_userId VARCHAR(100))
BEGIN
  SELECT * FROM products WHERE ProductType=1 AND Price<=400;
  SELECT * FROM products WHERE ProductType=1 AND Price<=700;
  SELECT * FROM products WHERE ProductType=2;
  SELECT * FROM products WHERE ProductType=3;
  SELECT * FROM details WHERE UserId=v_userId;
  SELECT * FROM detailsTwo WHERE UserId=v_userId;
END $$

DELIMITER ;

Seems there was confusion in all the userId variations.

Sign up to request clarification or add additional context in comments.

1 Comment

strange, userId to v_userId worked ,but "@v_userId" didn't. Thanks @Jacques Amar . you can edit ans if you want to(by removing "@" sign).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.