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 523957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:31:03+00:00 2026-05-13T08:31:03+00:00

I’m returning results from the following query which is taking too long when running.

  • 0

I’m returning results from the following query which is taking too long when running. I’m not sure how to eliminate the where parameters when they are not used in SSRS. All the @variables are strings

select S.SBSB_ID, LTRIM(RTRIM(M.MEME_FIRST_NAME)) + ' ' + 
LTRIM(RTRIM(M.MEME_LAST_NAME)) AS Names,
(CASE M.MEME_REL WHEN 'M' THEN 'Subscriber'
                             WHEN 'S' THEN 'Son'
                             WHEN 'D' THEN 'Daughter'
                             WHEN 'W' THEN 'Wife'
                             WHEN 'H' THEN 'Husband'
                             WHEN 'O' THEN 'Other'
                             ELSE M.MEME_REL END) AS Relation,
(CASE A.PRPR_ID WHEN 'NONASSIGNED' THEN A.CLCL_PA_ACCT_NO
                          ELSE LTRIM(P.PRPR_NAME) END) AS ProvName,
LTRIM(RTRIM(L.CDDL_CUR_STS)) AS Status
FROM CMC_SBSB_SUBSC S INNER JOIN CMC_MEME_MEMBER M 
ON S.SBSB_CK = M.SBSB_CK INNER JOIN CMC_CDDL_CL_LINE L 
ON L.MEME_CK = M.MEME_CK INNER JOIN CMC_PRPR_PROV P 
ON P.PRPR_ID = L.PRPR_ID INNER JOIN CMC_CLCL_CLAIM A 
ON A.CLCL_ID = L.CLCL_ID
WHERE 
S.SBSB_ID LIKE (CASE @subscriberID 
WHEN '' THEN '%' ELSE @subscriberID END) AND
M.MEME_REL IN (@Relation) AND
UPPER(M.MEME_FIRST_NAME) LIKE '%' + 
UPPER(CASE @firstName WHEN '' THEN '%' ELSE @firstName END) + '%' AND
UPPER(M.MEME_LAST_NAME) LIKE '%' + 
UPPER(CASE @lastName WHEN '' THEN '%' ELSE @lastName END) + '%' AND
(L.CGCG_ID IN (@Category) OR L.CGCG_ID = '') AND

(CASE WHEN (@Tooth) = '' THEN L.CDDL_TOOTH_BEG
WHEN ISNUMERIC(@Tooth) = 0 THEN UPPER(@Tooth)
WHEN LEN(@Tooth) = 1 THEN '0' + @Tooth
ELSE @Tooth END) >= L.CDDL_TOOTH_BEG AND

(CASE WHEN (@Tooth) = '' THEN L.CDDL_TOOTH_BEG
WHEN ISNUMERIC(@Tooth) = 0 THEN UPPER(@Tooth)
WHEN LEN(@Tooth) = 1 THEN '0' + @Tooth
ELSE @Tooth END) <= L.CDDL_TOOTH_END AND

S.SBSB_CK IN (select SBSB_CK FROM CMC_MEME_MEMBER 
WHERE MEME_SSN LIKE (CASE @SSN WHEN '' THEN '%' ELSE @SSN END)) AND
M.MEME_BIRTH_DT LIKE (CASE WHEN @DOB IS NULL THEN '%' ELSE @DOB END)

UNION

select S.SBSB_ID, LTRIM(RTRIM(M.MEME_FIRST_NAME)) + ' ' + 
LTRIM(RTRIM(M.MEME_LAST_NAME)) AS Names,
(CASE M.MEME_REL WHEN 'M' THEN 'Subscriber'
                             WHEN 'S' THEN 'Son'
                             WHEN 'D' THEN 'Daughter'
                             WHEN 'W' THEN 'Wife'
                             WHEN 'H' THEN 'Husband'
                             WHEN 'O' THEN 'Other'
                             ELSE M.MEME_REL END) AS Relation,
RTRIM(LTRIM(P.PRPR_NAME)) AS ProvName,
'Purged - ' + H.CLDH_STS AS Status
FROM CMC_SBSB_SUBSC S INNER JOIN CMC_MEME_MEMBER M 
ON S.SBSB_CK = M.SBSB_CK
INNER JOIN CMC_CLDH_DEN_HIST H ON H.MEME_CK = M.MEME_CK
INNER JOIN CMC_PRPR_PROV P ON P.PRPR_ID = H.PRPR_ID
WHERE 
S.SBSB_ID LIKE (CASE @subscriberID 
WHEN '' THEN '%' ELSE @subscriberID END) AND
M.MEME_REL IN (@Relation) AND
UPPER(M.MEME_FIRST_NAME) LIKE '%' + 
UPPER(CASE @firstName WHEN '' THEN '%' ELSE @firstName END) + '%' AND
UPPER(M.MEME_LAST_NAME) LIKE '%' + 
UPPER(CASE @lastName WHEN '' THEN '%' ELSE @lastName END) + '%' AND
(H.CGCG_ID IN (@Category) OR H.CGCG_ID = '') AND

(CASE WHEN (@Tooth) = '' THEN H.CLDH_TOOTH_BEG
WHEN ISNUMERIC(@Tooth) = 0 THEN UPPER(@Tooth)
WHEN LEN(@Tooth) = 1 THEN '0' + @Tooth
ELSE @Tooth END) >= H.CLDH_TOOTH_BEG AND

(CASE WHEN (@Tooth) = '' THEN H.CLDH_TOOTH_BEG
WHEN ISNUMERIC(@Tooth) = 0 THEN UPPER(@Tooth)
WHEN LEN(@Tooth) = 1 THEN '0' + @Tooth
ELSE @Tooth END) <= H.CLDH_TOOTH_END AND

S.SBSB_CK IN (select SBSB_CK FROM CMC_MEME_MEMBER 
WHERE MEME_SSN LIKE (CASE @SSN WHEN '' THEN '%' ELSE @SSN END)) AND
M.MEME_BIRTH_DT LIKE (CASE WHEN @DOB IS NULL THEN '%' ELSE @DOB END)

I would rather have the query not executing blank fields with ‘%’ but was not sure how to eliminate them conditionally from the query.

  • 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-13T08:31:03+00:00Added an answer on May 13, 2026 at 8:31 am
    1. Make sure you’ve got appropriate indexes on the database to support your query. Get the database to dump out the access plan and figure out what tables are being accessed using a full table scan rather than an index. Try to add indexes or hints or whatever to get rid of the full table scans.

    2. If you’re using Oracle or some other database which supports the NVL function you can rewrite

    .

    @Parameter = table.Fieldname OR @Parameter IS NULL
    

    as

    NVL(@Parameter, table.Fieldname) = table.Fieldname
    

    I’ve found this can improve performance dramatically as the second formulation is more likely to allow an index to be used while the first one often devolves into a full table scan.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.