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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:40:32+00:00 2026-06-03T08:40:32+00:00

I am running a query on SQL Server 2005 to look up records within

  • 0

I am running a query on SQL Server 2005 to look up records within a date range. The WHERE clause looks like this:

WHERE (CONVERT(NVARCHAR, fldPublishedDate, 101) >= '" & toDate & 
   "' AND CONVERT(NVARCHAR, fldPublishedDate, 101) <= '" & fromDate & "')"

toDate and fromDate are entered like this 04/01/2005 and 04/30/2005.

The results I am getting are definitely all between 1st and 30th of April but from various years, ranging from 2005 (when data collection started) to 2012. It looks like the year is simply ignored from the comparison. Am I missing something here?

Thank you for taking your time to read this.

  • 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-03T08:40:33+00:00Added an answer on June 3, 2026 at 8:40 am

    Why are you converting to a string? Of course this doesn’t work as expected. You’re saying:

    IF '12/02/2010' > '09/12/2012'
    

    Which of course yields true. You should be saying:

    WHERE fldPublishedDate >= '20050401'
      AND fldPublishedDate < DATEADD(DAY, 1, '20050430');
    

    You don’t need to convert the column to a date only if you’re only comparing date ranges. Most importantly you should be passing in dates in an unambiguous format that is immune from regional and language settings (e.g. YYYYMMDD). 101 isn’t a safe style because what month is 04/06/2012 for people in England? That’s June, not April. I suspect you should be formatting these dates better in your (classic ASP?) code, or passing in proper datetime data types from whatever language you’re using. Finally, don’t use NVARCHAR without length:

    • Bad habits to kick : declaring VARCHAR without (length)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long-running SQL Server 2005 query that I have been hoping to
I am having trouble running a simple sql query in Microsoft SQL Server 2005
I've got a simple query running against SQL Server 2005 SELECT * FROM Table
I am running a query in SQL Server 2005. The query needs to have
We're running our application's database on dedicated box running only SQL Server 2005. This
I'm running a query from SQL Server Management Studio 2005 that has an HTML
I'm running a SQL query on SQL Server 2005, and in addition to 2
This query works great in SQL Server 2005 and 2008. How would I write
I'm running SQL query for MySQL server with ... where name in (term1,term2,term3) I
Im running this query on the same server as the web application, so SPQuery.ExpandRecurrence

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.