We are SQL Server Experts. Call Us TODAY! +17738095456 or email us at sales@itimpact.com
  • The Team
  • Our Services
    • Dashboards Developers
    • Microsoft SQL Server
    • Microsoft SQL Server hosting for Access
    • SQL Server Integration Services (SSIS)
    • SQL Server Reporting Services (SSRS)
    • SQL Server Data Quality Services (DQS)
    • Microsoft Access
    • Microsoft VB.Net
    • Cross Functional / Business Unit Integration
    • Financial Statement Consolidation
    • Website Design
  • Case Studies
    • Automatic Reporting for Security Services Firm
    • Amazon API Integration with Access
    • Custom Quoting and Proposal Solution
    • Data Quality Analysis for Government Program
    • New Claim System Reduces Processing Time
    • Pipe Tracking Software
    • Product Search Analysis
    • Safety Training, Incident and Accident Tracking Tool
    • Union Dues and Membership Management System
  • Blog
  • Contact
  • The Team
  • Our Services
    • Dashboards Developers
    • Microsoft SQL Server
    • Microsoft SQL Server hosting for Access
    • SQL Server Integration Services (SSIS)
    • SQL Server Reporting Services (SSRS)
    • SQL Server Data Quality Services (DQS)
    • Microsoft Access
    • Microsoft VB.Net
    • Cross Functional / Business Unit Integration
    • Financial Statement Consolidation
    • Website Design
  • Case Studies
    • Automatic Reporting for Security Services Firm
    • Amazon API Integration with Access
    • Custom Quoting and Proposal Solution
    • Data Quality Analysis for Government Program
    • New Claim System Reduces Processing Time
    • Pipe Tracking Software
    • Product Search Analysis
    • Safety Training, Incident and Accident Tracking Tool
    • Union Dues and Membership Management System
  • Blog
  • Contact
Toggle panel Social icons
SQL Server

Querying SQL Server DateTime Fields in Access

The other day I was troubleshooting a query in Access that was using a SQL Server table and coming up short on the number of records retrieved. I knew I was supposed to get x records and instead was getting y. (First rule in designing queries is to always know the answer before you start building it, otherwise, how are you going to validate your query?).  One of my criteria fields was DateCreated, a datetime field in SQL Server. For some reason I wasn’t getting all of the records back for the date period specified.

Time Paradox
I finally nailed down what it was: when you use a date criteria, i.e.: between StartDate and EndDate you may not get back all of the records since all dates are stored with a time stamp.

In my case I was using a default value of getdate() on the field in my table. Getdate() will insert the date and time the record was committed, for example 4/11/2011 2:32:73 PM. I was aware of this behavior and the issues it causes with queries but had forgotten about it when I came across my problem.

Append Dawn and Midnight to your criteria
To capture all of the data I had to modify my criteria to include times, for example:

Between #4/1/2011 00:00:00 AM# And 4/30/2011 11:59:59 PM#

I was using a form where the user enters the start and ending dates for the analysis, so I had my code append the times:

strCriteria = “Between #” & txtStartDate & ” 00:00:00 AM# And #” & txtEndDate & ” 11:59:59 PM#”

But what if Access (or the user) enters the date?
When the user enters a date in the field or when Access does it via code there is no issue, the record is saved with 00:00:00 as the time portion and you can use dates with no time stamps to query the data.

 

 

Click here to cancel reply.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

XHTML: You can use these tags <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts

  • 23 Jan. 2019 7 essential SQL skills that can help you command a higher paycheck

  • 18 Jan. 2018 Quick Guide on Importing Data from SQL Server (or SQL Azure) to Cosmos DB

  • 10 Jan. 2018 Top 7 Questions about Basic Availability Groups

  • 04 Jan. 2018 An introduction to mssql-cli, a command-line client for SQL Server

  • Share and work together on the intranet with SharePoint Team Sites

ITImpact

About IT Impact, Inc.

IT Impact, Inc.

IT Impact, Inc. is a minority-owned software company specializing in custom software solutions. We work with SQL Server, Microsoft Access, web applications, and much more.

Our staff is top of the line and includes two Microsoft MVPs!

Twitter

Tweets by @ITImpactInc

Facebook

© ITImpact. Webdesign by GreatCustomWebsites.com