better query for select results based on date.

Jonathan Brotto 420 Reputation points
2024-09-30T19:03:37.35+00:00

What is the best way to write this code to get the date results? I have the time throughout the day in the datetime field.

SELECT * FROM Reconciliation.Documents D
Inner Join Reconciliation.DocumentsTransaction T
ON D.DocumentPKey = T.DocumentPKey
WHERE 
PartnerID = 'Busdepot' AND EDIDirection = 'inbound' 
and EDITransactionType = '850' 
and year(InsertTimestamp) = year('2024-09-18')
and month(InsertTimestamp) = month('2024-09-18')
and day(InsertTimestamp) = day('2024-09-18')
ORDER BY d.DocumentPKey

SQL Server | SQL Server Transact-SQL
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
{count} votes

Answer accepted by question author
  1. Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator
    2024-09-30T21:18:01.41+00:00
    WHERE insertTimestamp >= @date
      AND InsertTimestamp < dateadd(DAY, 1,  @date)
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.