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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:06:34+00:00 2026-06-15T20:06:34+00:00

I have to write a stored procedure to find whether the given date range

  • 0

I have to write a stored procedure to find whether the given date range is overlapping the list of Date Ranges in the table.

Ex)

Database: SQL Server 2008 R2

SP Input: 2012-12-17 18:30:00.000       2012-12-19 18:29:59.000

SP Output(Out parameter): True/False

Booking Table Sample Data:

FromDate                    ToDate

2012-12-11 18:30:00.000     2012-12-12 18:29:59.000
2012-12-12 18:30:00.000     2012-12-13 18:29:59.000
2012-12-10 18:30:00.000     2012-12-11 18:29:59.000
2012-12-18 18:30:00.000     2012-12-19 18:29:59.000
2012-12-23 18:30:00.000     2012-12-28 18:29:59.000
2012-12-17 18:30:00.000     2012-12-18 18:29:59.000
2012-12-19 18:30:00.000     2012-12-22 18:29:59.000
2012-12-16 18:30:00.000     2012-12-17 18:29:59.000
2012-12-13 18:30:00.000     2012-12-14 18:29:59.000
2012-12-11 23:00:00.000     2012-12-12 22:59:59.000

Stored Procedure:

USE [BookingDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[FindConflict]    
    @FromDate datetime,
    @ToDate datetime,
    @IsConflict bit OUT
AS

BEGIN

?????????????????????(what to write here)

END

SQL:

USE [BookingDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BookingAdmin](
    [PK_BookingAdmin] [int] IDENTITY(1000,1) NOT NULL,
    [FromDate] [datetime] NOT NULL,
    [ToDate] [datetime] NOT NULL,
 CONSTRAINT [PK_BookingAdmin] PRIMARY KEY CLUSTERED 
(
    [PK_BookingAdmin] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[BookingAdmin] ON
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1048, CAST(0x0000A1240130DEE0 AS DateTime), CAST(0x0000A1250130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1049, CAST(0x0000A1250130DEE0 AS DateTime), CAST(0x0000A1260130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1050, CAST(0x0000A1230130DEE0 AS DateTime), CAST(0x0000A1240130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1051, CAST(0x0000A12B0130DEE0 AS DateTime), CAST(0x0000A12C0130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1052, CAST(0x0000A1300130DEE0 AS DateTime), CAST(0x0000A1350130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1053, CAST(0x0000A12A0130DEE0 AS DateTime), CAST(0x0000A12B0130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1055, CAST(0x0000A12C0130DEE0 AS DateTime), CAST(0x0000A12F0130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1056, CAST(0x0000A1290130DEE0 AS DateTime), CAST(0x0000A12A0130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1057, CAST(0x0000A1260130DEE0 AS DateTime), CAST(0x0000A1270130DDB4 AS DateTime))
INSERT [dbo].[BookingAdmin] ([PK_BookingAdmin], [FromDate], [ToDate]) VALUES (1058, CAST(0x0000A124017B0740 AS DateTime), CAST(0x0000A125017B0614 AS DateTime))
GO


CREATE PROCEDURE [dbo].[FindConflict]    
    @FromDate datetime,
    @ToDate datetime,
    @IsConflict bit OUT
AS
BEGIN
    if exists (select * from BookingAdmin where FromDate = @ToDate and ToDate = @FromDate)
        set @IsConflict = 1   
    else
        set @IsConflict = 0        
END
  • 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-15T20:06:36+00:00Added an answer on June 15, 2026 at 8:06 pm

    If I understood your needs correctly, and you just need to check if there’s exactly the same range in the table, you can try this

    USE [BookingDB]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[FindConflict]    
        @FromDate datetime,
        @ToDate datetime,
        @IsConflict bit OUT
    AS
    BEGIN
        if exists (select * from <your table> where FromDate = @FromDate and ToDate = @ToDate)
            set @IsConflict = 1   
        else
            set @IsConflict = 0
    END
    

    update if you want to know about overlapping ranges, try this

     ...
        if exists (select * from <your table> where FromDate <= @ToDate and ToDate >= @FromDate)
            set @IsConflict = 1   
        else
            set @IsConflict = 0
     ...
    

    SQL FIDDLE EXAMPLE

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

Sidebar

Related Questions

The Problem I'm trying to write a stored procedure in SQL Server to find
I have to write one Stored Procedure, In which I have to find the
I have to write a update stored procedure. I will be asking paramters for
I have a stored procedure in which if I write the following query without
I have a stored procedure (that I didn't write) that uses openquery to populate
On our SQL Server (Version 10.0.1600), I have a stored procedure that I wrote.
We have a SQL Server 2008 database that has stored procedures to handle reads/writes/etc.
I have one database. I executed a stored procedure on it. I wrote some
I'm trying to write a stored procedure that will have 6 bit value flags
We have an stored procedure that we created so that user can write comma

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.