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

  • Home
  • SEARCH
  • 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 6660049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:06:24+00:00 2026-05-26T02:06:24+00:00

I am trying to append condition to where clause .But the string which contains

  • 0

I am trying to append condition to where clause .But the string which contains the condition is not working .I am not getting any error but the condition is not fully applied in the query

Here’s the query.I am passing CLINIC_ID and taleEnd to my stored procedure.taleEnd will include a condition or more like this – “and DOS between ‘2011-09-08’ and ‘2011-10-08′”

SELECT *
  FROM A
  JOIN B ON C.CLINIC_ID = VP.CLINIC_ID AND C.CLAIM_ID = VP.CLAIM_ID
  JOIN C ON P.CLINIC_ID = VP.CLINIC_ID  AND P.PATIENT_ID = VP.PATIENT_ID
  JOIN D ON I.CLINIC_ID = C.CLINIC_ID  AND I.INSURANCE_ID= C.PRIMARY_INSURANCE_ID
  JOIN E ON B.CLINIC_ID = I.CLINIC_ID  AND B.BUSINESS_ID= I.COMPANY_ID
 WHERE (VP.STATUS = 3 OR VP.STATUS = 5)
   AND VP.PRIMARY_PAID = 0
   AND VP.PRIMARY_PENDING > 0
   AND C.PRIMARY_PAYER_ID > 0
   AND C.HIDEN = 0
   AND VP.CLINIC_ID = CLINIC_ID + taleEnd

The problem is that only clinic_id and not DOS is applied when i run the stored procedure.I tried concat ,set but nothing worked.i didn’t got any error but the result do not applies DOS.Can any one help me please.

@Devart This is the store procedure.

CREATE DEFINER=`root`@`%` PROCEDURE `PRIMARY_INSURANCE_AGING`(CLINIC_ID INT,taleEnd TEXT)
BEGIN
DROP TEMPORARY TABLE IF EXISTS PRIMARY_TEMP;
CREATE TEMPORARY TABLE PRIMARY_TEMP
SELECT *     
  FROM A   
  JOIN B ON C.CLINIC_ID = VP.CLINIC_ID AND C.CLAIM_ID = VP.CLAIM_ID   
  JOIN C ON P.CLINIC_ID = VP.CLINIC_ID AND P.PATIENT_ID = VP.PATIENT_ID   
  JOIN D ON I.CLINIC_ID = C.CLINIC_ID  AND I.INSURANCE_ID= C.PRIMARY_INSURANCE_ID   
  JOIN E ON B.CLINIC_ID = I.CLINIC_ID  AND B.BUSINESS_ID= I.COMPANY_ID 
 WHERE (VP.STATUS = 3 OR VP.STATUS =5 ) 
   AND VP.PRIMARY_PAID = 0   
   AND VP.PRIMARY_PENDING > 0   
   AND C.PRIMARY_PAYER_ID > 0   
   AND C.HIDEN = 0  
   AND VP.CLINIC_ID = CLINIC_ID + taleEnd;

   END

This is the usage of Prepare statement

SET @A = CONCAT(34847," and DOS between '2011-09-08' and '2011-10-08'");
PREPARE STMT FROM '
SELECT *
  FROM A
  JOIN B ON C.CLINIC_ID = VP.CLINIC_ID AND C.CLAIM_ID = VP.CLAIM_ID
  JOIN C ON P.CLINIC_ID = VP.CLINIC_ID AND P.PATIENT_ID = VP.PATIENT_ID
  JOIN D ON I.CLINIC_ID = C.CLINIC_ID AND I.INSURANCE_ID= C.PRIMARY_INSURANCE_ID
  JOIN E ON B.CLINIC_ID = I.CLINIC_ID AND B.BUSINESS_ID= I.COMPANY_ID
  WHERE (VP.STATUS = 3 OR VP.STATUS = 5)
  AND VP.PRIMARY_PAID = 0
  AND VP.PRIMARY_PENDING > 0
  AND C.PRIMARY_PAYER_ID > 0
  AND C.HIDEN = 0
  AND VP.CLINIC_ID ? ';

EXECUTE STMT USING @A;
  • 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-26T02:06:24+00:00Added an answer on May 26, 2026 at 2:06 am

    Agree with Dave Rix about the variable and field names, they should be different.

    If you want to append additional string (like – and DOS between ‘2011-09-08’ and ‘2011-10-08’) to the query, then you should use a prepared statement.

    EDIT:

    Example:

    SET @query = 'SELECT *
    FROM A
    JOIN B ON C.CLINIC_ID = VP.CLINIC_ID AND C.CLAIM_ID = VP.CLAIM_ID
    JOIN C ON P.CLINIC_ID = VP.CLINIC_ID AND P.PATIENT_ID = VP.PATIENT_ID
    JOIN D ON I.CLINIC_ID = C.CLINIC_ID AND I.INSURANCE_ID= C.PRIMARY_INSURANCE_ID
    JOIN E ON B.CLINIC_ID = I.CLINIC_ID AND B.BUSINESS_ID= I.COMPANY_ID WHERE (VP.STATUS = 3 OR VP.STATUS =5 ) AND VP.PRIMARY_PAID = 0
    AND VP.PRIMARY_PENDING > 0
    AND C.PRIMARY_PAYER_ID > 0
    AND C.HIDEN = 0
    AND VP.CLINIC_ID = ?'; -- ? will be supplied with procedure argument clinic_id_value; where clinic_id_value is a renamed procedure argument
    
    IF taleEnd IS NOT NULL THEN
      @query = CONCAT(@query, ' ', taleEnd);
    END IF;
    
    SET @clinic_id_value = clinic_id_value; -- copy procedure argument to the local variable
    PREPARE STMT FROM @query;
    EXECUTE STMT USING @clinic_id_value;
    DEALLOCATE PREPARE STMT;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to append this string: <div> hello </div> as an HTML node, but
I'm trying to append a string of svg elements to the dom. This is
I'm trying to append items to a QList at runtime, but I'm running on
I'm trying to append a value only if a condition is met (distance !=
I'm trying to append tp-lightboxactitem into tp-lightboxcontainer . Can any one help me with
I am trying to append to a string in a for loop. I can
I'm trying to append the following table built up in a string to a
I'm trying to get matches of single bracket followed by a non-space, but not
I'm trying to append a strings which end in newlines to a textarea using
I am trying to append a html tag for an 'onkeyup' event. But I

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.