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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:23:16+00:00 2026-05-22T16:23:16+00:00

The following is my SP : Alter PROCEDURE GetList ( @FromDate date = null,

  • 0

The following is my SP:

Alter PROCEDURE GetList 
(

@FromDate date = null,
@ToDate date = null

)
AS

Select * FROM CallList c
Where c.CallDate > @FromDate and c.CallDate < @ToDate 

If there was no passed date filter, I want to get all the records.

How would I do it?

  • 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-22T16:23:17+00:00Added an answer on May 22, 2026 at 4:23 pm

    A couple of viable options:

    You could set @FromDate and @ToDate to be equal to a very early or very late date respectively they’re NULL.

    You could use sp_executesql and construct a dynamic query string w/ parameters as needed e.g.

    DECLARE @Sql NVARCHAR(MAX) = 'SELECT * FROM CallList C WHERE 1 = 1 '
    
    IF @FromDate IS NOT NULL
    BEGIN
      SET @Sql += ' AND C.CallDate > @xFromDate'
    END
    
    IF @ToDate IS NOT NULL
    BEGIN
      SET @Sql += ' AND C.CallDate < @xToDate'
    END
    
    EXEC sp_executesql @Sql, N'@xFromDate DATETIME, @xToDate DATETIME', @xFromDate = @FromDate, @xToDate = @ToDate
    

    This latter approach performs better than using ORs all over the place, as queries that include ORs invariably end up getting optimized very badly – they might work well for a certain set of parameters but are generally not one-size-fits-all.

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

Sidebar

Related Questions

I have the following search sql query: ALTER PROCEDURE [EmployeeSearch] @PayrollNumber varchar(50) = null,
I am using following storedprocedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO Alter PROCEDURE
I have the following SQL: ALTER PROCEDURE [dbo].[SP_Products_GetList] @CatID int, @CatName int, @SortBy varchar(50),
I have the following stored procedure: ALTER PROCEDURE Pro_members_Insert @id int outPut, @LoginName nvarchar(50),
I have the following stored procedure ALTER PROCEDURE [dbo].Test AS BEGIN CREATE TABLE ##table
I have the following Stored Procedure ALTER PROCEDURE [dbo].[bt_BizForSale_GetByID] ( @ID int ) AS
I have the following stored procedure. ALTER PROCEDURE [dbo].[spList_Report] @id INT, @startDate DATETIME =
I have a stored procedure with the following code. alter PROCEDURE [dbo].[usp_Product_GetProductByCategoryID] @CategoryID uniqueidentifier,
I use the following stored procedure from my SQL Server 2008 database to return
Hi i have the following stored proc in SQL Server 2005: ALTER PROCEDURE [dbo].[slot_sp_EngineerTimeslots_Group]

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.