Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6718293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:07+00:00 2026-05-26T08:57:07+00:00

The below SP is not giving any result even though there are 48 rows

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:57:08+00:00Added an answer on May 26, 2026 at 8:57 am
    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
    
    1. All declaration have to be at the begining.
    2. Rename @SelectClause to SelectClause, because you are declaring this variable.
    3. Check the usage of SET clauses. I have added one.
    4. Have a look at prepared statements reference, it will help you to execute the query you built.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below Declare @tbl Table(Id int identity, SomeCol varchar(10) not null) Begin
Below roundtrip produces invaild xml as the result is not escaped correctly, i.e. the
I would like to solve rounding mechanism by using php4,5.2 and below (not 5.3)
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
The below does not compile: Func<int, int> fac = n => (n <= 1)
The XAML below does not work (the text does not change when mousing over):
The question below is not really a programming question, but more of how can
I have this horrible habit of typing the below and not catching it until
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.