Note that there are some explanatory texts on larger screens.

plurals
  1. POMySql stored procedure with limit parameters gives err.no : 1064 when we use CONCAT statement
    primarykey
    data
    text
    <p>We have a long sql procedure that takes limit &amp; amount(limitCount) parameters. So, we are using concat statement for joining multiple queries. Calling this procedure gives err.no 1064 when we try to run it. </p> <p>EDIT : Based on the comment, I'm adding the whole code. </p> <pre><code>CREATE PROCEDURE getProfileTasks (IN p_id1 INT, IN p_id2 INT , IN limitStart INT, IN limitCount INT) BEGIN SET @SQL = CONCAT(' SELECT P.access_type INTO @privacy FROM Profile P WHERE P.profile_id = ' , p_id2 , '; IF( ' , p_id1, ' = ' ,p_id2 , ') THEN SELECT T.task_id, T.name, D.add_time, D.location, DATE_FORMAT(D.date1, "%d/%m/%y") as `date1`, D.time3, D.state, TIME_FORMAT(D.time1, "%H:%i")as `time1`, D.does_id, IFNULL(L.Like, 0) AS `LikeCount` , IFNULL(C.CommentCount,0) AS `CommentCount` FROM Task T INNER JOIN Does D on D.task_id = T.task_id INNER JOIN Profile P on P.profile_id = D.profile_id LEFT OUTER JOIN ( SELECT D.does_id, COUNT(L.profile_id) as `Like` FROM `Likes` L INNER JOIN Does D on D.does_id = L.does_id INNER JOIN Profile P on P.profile_id = D.profile_id WHERE P.profile_id = ' , p_id2 , ' GROUP BY does_id) L on L.does_id = D.does_id LEFT OUTER JOIN( SELECT D.does_id, COUNT(C.content) AS `CommentCount` FROM Comment C INNER JOIN Does D on D.does_id = C.does_id GROUP BY (D.does_id)) C ON C.does_id = D.does_id WHERE P.profile_id= ' , p_id2, ' ORDER BY D.add_time DESC LIMIT ' , limitStart , ', ' , limitCount, '; ELSE IF (@privacy = 0) THEN SELECT T.task_id, T.name, D.add_time, D.location, DATE_FORMAT(D.date1, "%d/%m/%y") as `date1`, D.time3, D.state, TIME_FORMAT(D.time1, "%H:%i")as `time1`, D.does_id, IFNULL(L.Like,0) AS `LikeCount`, IFNULL(C.CommentCount,0) AS `CommentCount` FROM Task T INNER JOIN Does D on D.task_id = T.task_id INNER JOIN Profile P on P.profile_id = D.profile_id LEFT OUTER JOIN ( SELECT D.does_id, COUNT(L.profile_id) as `Like` FROM `Likes` L INNER JOIN Does D on D.does_id = L.does_id INNER JOIN Profile P on P.profile_id = D.profile_id WHERE P.profile_id = ' , p_id2 , ' GROUP BY does_id) L on L.does_id = D.does_id LEFT OUTER JOIN( SELECT D.does_id, COUNT(C.content) AS `CommentCount` FROM Comment C INNER JOIN Does D on D.does_id = C.does_id GROUP BY (D.does_id) )C ON C.does_id = D.does_id WHERE P.profile_id= ' ,p_id2, ' ORDER BY D.add_time DESC LIMIT ' , limitStart , ', ' , limitCount, '; ELSE IF EXISTS ( SELECT * FROM Follows F INNER JOIN Profile P on F.follower_id = P.profile_id INNER JOIN Profile P2 on F.following_id = P2.profile_id WHERE (P.profile_id = ' , p_id1, ' AND P2.profile_id = ' , p_id2 , ')) THEN SELECT T.task_id, T.name, D.add_time, D.location, DATE_FORMAT(D.date1, "%d/%m/%y") as `date1`, D.time3, D.state, TIME_FORMAT(D.time1, "%H:%i")as `time1`, D.does_id, IFNULL(L.Like,0) AS `LikeCount`, IFNULL(C.CommentCount,0) AS `CommentCount` FROM Task T INNER JOIN Does D on D.task_id = T.task_id INNER JOIN Profile P on P.profile_id = D.profile_id LEFT OUTER JOIN ( SELECT D.does_id, COUNT(L.profile_id) as `Like` FROM `Likes` L INNER JOIN Does D on D.does_id = L.does_id INNER JOIN Profile P on P.profile_id = D.profile_id WHERE P.profile_id = ' , p_id2 , ' GROUP BY does_id) L on L.does_id = D.does_id LEFT OUTER JOIN( SELECT D.does_id, COUNT(C.content) AS `CommentCount` FROM Comment C INNER JOIN Does D on D.does_id = C.does_id GROUP BY (D.does_id) )C ON C.does_id = D.does_id WHERE P.profile_id= ' , p_id2 , ' ORDER BY D.add_time DESC LIMIT ' , limitStart , ', ' , limitCount, '; END IF; END IF; END IF; ' ); PREPARE query FROM @SQL; EXECUTE query; DEALLOCATE PREPARE query; END </code></pre> <p>Anyone has any idea about why we are getting this error ? </p> <pre><code>ERROR : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF( 18 = 18) THEN SELECT T.task_id, T.name, D.add_time, D.location, DATE_' at line 2 </code></pre> <p>P.S : DELIMITER is set to // </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload