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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:21:41+00:00 2026-05-28T00:21:41+00:00

I have a query with the below WHERE clauses WHERE I.new_outstandingamount = 70 AND

  • 0

I have a query with the below WHERE clauses

WHERE
    I.new_outstandingamount = 70
    AND ISNUMERIC(SUBSTRING(RA.new_stampernumber,7, 4)) = 1
    AND (DATEDIFF(M,T.new_commencementdate, SUBSTRING(RA.new_stampernumber,7, 10)) >= 1)
    AND RA.new_applicationstatusname = 'Complete'
    AND I.new_feereceived > 0
    AND RA.new_stampernumber IS NOT NULL
    AND T.new_commencementdate IS NOT NULL

RA.new_stampernumber is a string value which contains three concatenated pieces of information of uniform length. The middle piece of info in this string is a date in the format yyyy-MM-dd.

In order to filter out any rows where the date in this string in not formatted as expected I do a check to see if the first 4 characters are numeric using the ISNUMERIC function.

When I run the query I get an error message saying

The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.

The line that is causing this error to occur is

AND (DATEDIFF(M,T.new_commencementdate, SUBSTRING(RA.new_stampernumber,7, 10)) >= 1)

When I comment out this line I don’t get an error.

What is strange is that if I replace

AND ISNUMERIC(SUBSTRING(RA.new_stampernumber,7, 4)) = 1

with

AND SUBSTRING(RA.new_stampernumber,7, 4) IN ('2003','2004','2005','2006','2007','2008','2009','2010', '2011', '2012','2013','2014','2015'))

the query runs successfully.

Whats even more strange is that if I replace the above working line with this

AND SUBSTRING(RA.new_stampernumber,11, 1) = '-'

I get the error message again. But if I replace the equals sign with a LIKE comparison it works:

AND SUBSTRING(RA.new_stampernumber,11, 1) LIKE '-'

When I remove the DATEDIFF function and compare the results of each of these queries they all return the same resultset so it is not being caused by different data being returned by the different clauses.

Can anyone explain to me what could be causing the out-of-range error to be thrown for some clauses and not for others if the data being returned is in fact the same for each clause?

Thanks,
Neil

  • 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-28T00:21:42+00:00Added an answer on May 28, 2026 at 12:21 am

    Different execution plans.

    There is no guarantee that the WHERE clauses are processed in particular order. Presumably when it works it happens to filter out erroring rows before attempting the cast to date.

    Also ISNUMERIC itself isn’t very reliable for what you want. I’d change the DATEDIFF expression to something like the below

    DATEDIFF(M, T.new_commencementdate, 
                        CASE
                        WHEN RA.new_stampernumber LIKE 
                        '______[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]%' 
                         THEN SUBSTRING(RA.new_stampernumber, 7, 10)
                         END) >= 1 ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query below that I use to retrieve the records not updated
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
We have the query below. Using a LEFT OUTER join takes 9 seconds to
I have the query below that when run it says that 325 rows were
I have below query I am trying to show message 'No SubSource for this
I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
I have an SQL query (below) that essentially takes a student from tbStudents, and
The query below returns rows that have both loginid and ip2 in the bumps
I have the below query in a postgresql database SELECT * FROM accounts where
I get the following error in the query below: #1064 - You have an

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.