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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:55:48+00:00 2026-06-12T22:55:48+00:00

There is a report whose query is using isnull in the where clause and

  • 0

There is a report whose query is using isnull in the where clause and it’s causing some performance issues.
Here is a very simplified example.
http://www.sqlfiddle.com/#!6/79759/11

The query is using a multi-valued parameter, usually just returning one or two values. (I’ve tried to replicate the SSRS multi-value param using a table variable in sqlfiddle)

select 
  isnull(descrL,descr) as division,
  product
from Upper
left join Lower on product = productL
where isnull(DescrL,Descr) in (@params)

There is an Upper division that has all the products. Some of the products exist on a child division. If it exists in the lower division, that is the division that should be shown.

The company parameter can accept the upper division, lower division, or both.

Any ideas on how the query can be changed for better performance?

  • 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-06-12T22:55:49+00:00Added an answer on June 12, 2026 at 10:55 pm
    select  descrL as division, product
    from Lower 
    where DescrL like @params + '%'
    union
    Select descr, product
    from Upper
    where Descr like @params = '%'
    

    This would be very performant. If the match is found in the top select, it should be suppressed in the bottom select since it’s a union instead of a union all. Notice the like instead of in. If you do an in there is just no way to use an index on DescrL or Descr to find the results. If you do a like, indexes are used fine. You may have to adjust your application logic to make that work.

    If you can’t do that, then there is this solution. You’ll have to add fn_split to your db. http://msdn.microsoft.com/en-us/library/aa496058(v=sql.80).aspx

        select  descrL as division, product
        from Lower l 
        join dbo.fn_Split(@params, ',') p1
            on l.DescrL = p1.value
        union
        Select descr, product
        from Upper u 
        join dbo.fn_Split(@params, ',') p2
            on u.Descr = p2.value
    

    If you really want to eke out the very last bit of performance you can declare a table variable and only run the fn_split once in order to populate the table variable, and then make the two joins be to the table variable. So here you are also taking advantage of the index on the columns, which is the main thing you need to make the query faster. Always do ‘include actual execution plan’ in sql server when you run it, and look at the results and make sure you’re seeing index seeks instead of table scans.

    EDIT: I went over to your sqlfiddle link. Didn’t see it earlier. This works. The union by itself won’t suppress dupes, since you are also selecting the division, sorry. So you have to use a not in, or as I prefer, a left outer where null.

    select descrL as division, productL as product
        from Lower l 
        join @params p1
            on l.DescrL = p1.division
        union
        Select u.descr, u.product
        from Upper u 
        join @params p2
            on u.Descr = p2.division
        left join (select productL as product
                    from Lower l2 
                   join @params p3
                     on l2.DescrL = p3.division) sub1
         on u.product = sub1.product
            where sub1.product is null
    order by 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So , I am creating a forum using php, Now there's a report button
In our report generation application, there's some pretty hefty queries that take a considerable
Is there any way to conditionally ( based on report parameter for example )
We have a report in Crystal Reports. On that report there is a general
Is there a way to report every mouse click on the application dock icon?
Is there a way to externalize report queries for BIRT reports. We need to
Is there a way to get a report of how long each test is
is there a way to create a task/activity report (say a weekly report) off
I am creating a report in SSRS 2005 and where there should be a
In report view in a CListCtrl in MFC, how do I detect if there

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.