A
A
AlexCruel2022-02-12 08:20:25
Transact SQL
AlexCruel, 2022-02-12 08:20:25

How to extract records by T-SQL date range?

Microsoft Documentation:
https://docs.microsoft.com/ru-ru/sql/t-sql/languag...

Quote:

The following example returns rows where datetime values ​​are between '20011212' and '20020105' inclusive.

SELECT BusinessEntityID, RateChangeDate  
FROM HumanResources.EmployeePayHistory  
WHERE RateChangeDate BETWEEN '20011212' AND '20020105';

Nothing actually happened.
Did the request - produces only the last record by date.
SELECT * FROM [Таб1]
WHERE ([Id] = '10') AND ([Дата] BETWEEN '2020-11-09 00:00:00.000' AND '2020-10-10 00:00:00.000')

So how can you raise records between a certain date range?
datetime data type.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2022-02-12
@tsklab

The date representation depends on the settings.

SELECT * FROM [Таб1]
WHERE ([Дата] BETWEEN '20201109' AND '20201010')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question