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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:38:10+00:00 2026-06-09T21:38:10+00:00

I have an academic scenario, which I would like to know how to analyse.

  • 0

I have an academic scenario, which I would like to know how to analyse.

DECLARE @date DATETIME
SET     @date = getDate()
SET     @date = DATEADD(DAY, DATEDIFF(DAY, 0, @date-3), 3)

This will round the date down to a Thursday.

What I have been challenged on is to evidence where there are implicit CASTs.

The are three places where I presume that this must be occuring…

DATEADD(
  DAY,
  DATEDIFF(
    DAY,
    0,          -- Implicitly CAST to a DATETIME?
    @date-3     -- I presume the `3` is being implicitly cast to a DATETIME?
  ),
  3             -- Another implicit CAST to a DATETIME?
)

Perhaps, however, as the 0 and 3‘s are are constants, this is done during compilation to an execution plan?

But if the 3‘s were INT variables, would that be different?

Is there a way to analyse an execution plan, or some other method, to be able to determine this imperically?

To make matters more complicated, I’m currently off site. I’m trying to remotely assist a colleague with this. Which means I do not have direct access to SSMS, etc.

  • 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-09T21:38:11+00:00Added an answer on June 9, 2026 at 9:38 pm

    For the queries

    DECLARE @date DATETIME  = getDate()
    DECLARE @N INT = 3
    
    SELECT  DATEADD(DAY, DATEDIFF(DAY, 0, @date-3), 3)
    FROM master..spt_values
    
    SELECT  DATEADD(DAY, DATEDIFF(DAY, 0, @date-@N), @N)
    FROM master..spt_values
    

    And looking at the execution plans the compute scalars show the following.

    Query 1

    [Expr1003] = Scalar Operator(dateadd(day,datediff(day,'1900-01-01 00:00:00.000',[@date]-'1900-01-04 00:00:00.000'),'1900-01-04 00:00:00.000'))
    

    Query 2

    [Expr1003] = Scalar Operator(dateadd(day,datediff(day,'1900-01-01 00:00:00.000',[@date]-CONVERT_IMPLICIT(datetime,[@N],0)),CONVERT_IMPLICIT(datetime,[@N],0)))
    

    showing that your suspicion is correct that it happens at compile time for the literal values but needs a CONVERT_IMPLICIT at run time for the int variables

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

Sidebar

Related Questions

I have a thread safe observable collection replacement which I would like to write
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have a list that I would like to be able to enumerate so
I have the following question: First of all, I know (and have some academic
I have set of files (which are essentially .exe files) that I allow the
I have the academic distribution of EPD 7.1 for MacOS 10.6.x , which has
I have an array with academic years: $arrayAcademicYears = array( array(8889, 1988-1989), array(8990, 1989-1990),
It's common practice for tables of regression outcomes in academic papers to have a
I've created a custom module citation for academic references. Citations have, among other things,
have written this little class, which generates a UUID every time an object of

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.