Reputation: 5459
The below SP is not giving any result even though there are 48 rows as per the where clause
BEGIN
DECLARE SelectClause VARCHAR(2000);
if v_mode='SearchByString' then
SET SelectClause ='select SURVEY_USER.username,SURVEY.* from SURVEY, SURVEY_USER';
if v_SearchString is not null then
SET SelectClause=CONCAT(@SelectClause,' where ');
Set SelectClause=CONCAT(@SelectClause,v_SearchString);
end if;
SET SelectClause=CONCAT(@SelectClause,' order by SURVEY.created_date DESC;') ;
select SelectClause;
SET @query = SelectClause;
PREPARE stmt FROM @query;
EXECUTE stmt;
select stmt;
end if;
END
I tried a lot but not getting any problem. I also tried select clause to print the command at various places to not able to print it. Please give me some solution. There are my parameters that I am passing v_mode='SearhByString' v_SearchString='SURVEY_USER.username=chiragfanse'
It should return 48 rows but does not return anything.
Upvotes: 0
Views: 124
Reputation: 122042
BEGIN
DECLARE SelectClause VARCHAR(2000);
IF v_mode = 'SearchString' THEN
SET SelectClause = CONCAT('select SURVEY_USER.username,SURVEY.* from SURVEY, SURVEY_USER');
IF SearchString IS NOT NULL THEN
SET SelectClause = CONCAT(SelectClause, ' where ', SearchString);
END IF;
SET SelectClause = CONCAT(SelectClause, ' order by SURVEY.created_date DESC;');
SET @query = SelectClause;
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END
Upvotes: 2
Reputation: 1520
you have wrong concat functions. Try this.
if v_mode='SearchString' then
DECLARE @SelectClause varchar(2000);
SET @SelectClause =CONCAT(select (SURVEY_USER.username,SURVEY.*) from SURVEY, 'SURVEY_USER');
if SearchString is not null then
@SelectClause=CONCAT(@SelectClause, 'where' ,SearchString);
end if;
SET @SelectClause=@SelectClause
order by SURVEY.created_date DESC
execute(@SelectClause)
end if;
try this. let me know if you need anything else.
Upvotes: 0