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
SQL Server Other
{count} votes

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