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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:21:45+00:00 2026-05-26T01:21:45+00:00

I have a query like : SELECT .. FROM … WHERE … AND ISNULL(ICA.actual_appearance_date,

  • 0

I have a query like :

SELECT ..
        FROM ...
        WHERE ...
        AND ISNULL(ICA.actual_appearance_date, ICA.scheduled_appearance_date)  
            BETWEEN LO.order_start_date 
                AND ISNULL(LO.actual_expiry_date, LO.expected_expiry_date)

Is there a neat way to only check that the actual_appearance_date is between the start and end date, but not include time?

So:

Appearance Date is 03/Oct/2011 @ 14h00… and the dates we’re check are 03/Oct/2011 @ 15h00 and and 07/Oct/2011 @ 10h00.

At the moment, that would not yield a result because of the time factors. I need to do a between on the date part only… So, between 03/Oct/2011 @ 0h00 and really 08/Oct/2011 @ 0:00.

Is there a neat way to do this?

Edit:

We’re developing for a 2008 machine, but we’re developing ON 2005 machines. Long story, but I can’t use the nice and neat DATE fix.

I am trying the DATEADD method, but am finding an issue.

This is not returning the result I expect:

DECLARE  @Table TABLE
(
    StartDate DATETIME,
    EndDate DATETIME
)

INSERT INTO @Table VALUES ('02-Jan-2011 13:00:00', '07-Jan-2011 15:30:00')

SELECT * FROM @Table
DECLARE @Date DATETIME
SET @Date = '07-Jan-2011 16:00:00'

SELECT
    CASE WHEN 
        @Date BETWEEN DATEADD(dd,DATEDIFF(dd,0,StartDate),0) AND DATEADD(dd, DATEDIFF(dd,0,EndDate),0)-- must cover the appearance date or still open
    THEN 1
    ELSE 0
    END AS Result
FROM @Table

Must I add +1 to the BETWEEN dates to include the last date? ‘BETWEEN’ doesn’t seem to be inclusive of the last date..

  • 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-26T01:21:46+00:00Added an answer on May 26, 2026 at 1:21 am

    You have SQL Server 2008 so just cast to date

    SELECT .. 
    FROM ... 
    WHERE ... AND 
         CAST(ISNULL(ICA.actual_appearance_date, ICA.scheduled_appearance_date) AS date)
            BETWEEN
               CAST(LO.order_start_date AS date)
            AND 
               CAST(ISNULL(LO.actual_expiry_date, LO.expected_expiry_date) AS date)
    

    For SQL Server 2005 and earlier, use the DATEDIFF/DATEADD trick: Best approach to remove time part of datetime in SQL Server

    Do not use varchar or float conversions

    Edit:, for SQL Server 2005

    You need to apply the DATEADD/DATEDIFF to all values

    ...
    SELECT
        CASE WHEN 
             DATEADD(dd,DATEDIFF(dd,0,@Date),0)
                  BETWEEN DATEADD(dd,DATEDIFF(dd,0,StartDate),0)
                  AND DATEADD(dd, DATEDIFF(dd,0,EndDate),0)
        THEN 1
        ELSE 0
        END AS Result
    FROM @Table
    

    Or

    WHERE ... AND 
         DATEADD(dd,DATEDIFF(dd,0,ISNULL(ICA.actual_appearance_date, ICA.scheduled_appearance_date),0)
            BETWEEN
               DATEADD(dd,DATEDIFF(dd,0,LO.order_start_date),0)
            AND 
               DATEADD(dd,DATEDIFF(dd,0,ISNULL(LO.actual_expiry_date, LO.expected_expiry_date),0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights
I have a query like so : SELECT * FROM table WHERE premium =
If I have a query like: Select EmployeeId From Employee Where EmployeeTypeId IN (1,2,3)
I have a simple query like this: select * from mytable where id >
I have an query like: SELECT id as OfferId FROM offers WHERE concat(partycode, connectioncode)
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have a query like this: SELECT t1.id, (SELECT COUNT(t2.id) FROM t2 WHERE t2.id
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
Right now, I have a SQL Query like this one: SELECT X, Y FROM
I have a query that looks a bit like this: SELECT weekEnd, MAX(timeMonday) FROM

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.