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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:45:47+00:00 2026-05-29T09:45:47+00:00

I am using the following SQL in my stored procedure to not filter by

  • 0

I am using the following SQL in my stored procedure to not filter by date parameters if they are null.

WHERE (Allocated >= ISNULL(@allocatedStartDate, '01/01/1900') 
       AND Allocated <= ISNULL(@allocatedEndDate,'01/01/3000'))
AND
(MatterOpened >= ISNULL(@matterOpenedStartDate, '01/01/1900') 
 AND MatterOpened <= ISNULL(@matterOpenedEndDate, '01/01/3000'))

Will this give any kind of performance hit when dealing with a lot of records?

Is there a better way to do this?

Number of records – around 500k

  • 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-29T09:45:48+00:00Added an answer on May 29, 2026 at 9:45 am

    Or just let the query optimizer have it:

    WHERE ( @allocatedStartDate is NULL or Allocated >= allocatedStartDate ) and
       ( @allocatedEndDate is NULL or Allocated <= @allocatedEndDate ) and
       ( @matterOpenedStartDate is NULL or MatterOpened >= @matterOpenedStartDate ) and
       ( @matterOpenedEndDate is NULL or MatterOpened <= @matterOpenedEndDate )
    

    Note that this is not logically equivalent to your query. The last line uses column MatterOpened, not Allocated, as I assume that was a typographic error.

    If performance is really an issue, you may want to consider adding indexes and changing the stored procedure to execute different queries based on the parameters. At least break it into: no filter, filter only on Allocated, filter only on MatterOpened, filter on both columns.

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

Sidebar

Related Questions

Why can the Linq to SQL designer not understand the following stored procedure and
If, using the following code in a MS SQL Server 2008 stored procedure: DECLARE
I want to do the following using SQL Server 2005. Create a stored procedure
I am using a Microsoft SQL Server 2005 stored procedure to post records in
I've got the a SQL Server stored procedure with the following T-SQL code contained
Using a stored procedure i have a fairly complex SQL statement which returns a
I've the following MS SQL stored procedure. I need to sort the results without
I need to run a stored procedure on SQL Server, using LINQ, and throw
I'm currently using the following SQL for retrieving the last seven days worth of
Hi i am using the following dynamic sql: declare @cmd nvarchar(4000) set @cmd= 'select

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.