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
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,214 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
108 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,670 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 114.6K Reputation points MVP
    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 Answers by the question author, which helps users to know the answer solved the author's problem.