SQL: how to display records in just 30 days

I tried to use

SELECT * from Results
WHERE DATEDIFF(d,Date,getdate())<30

But this seems like a mistake.

Only 30 days will be displayed for each registered entry. Can I find out if my syntax is correct?

Famous, Stan

+3
source share
6 answers

The syntax looks fine, but you may need to quote Date:

SELECT * from Results WHERE DATEDIFF(d, [Date], getdate()) < 30

Do you have a Date in Results column?

BTW, which will not be able to use the index, whereas it will be:

SELECT * from Results WHERE [Date] >= DATEADD(d, -30, getdate()) 
+13
source

-, ( ) SQL. SQL Server, SQL Server (.. GetDate()).

JohnFx Jet SQL:

SELECT *  
FROM results 
WHERE ([Date] between DateAdd("d", -30, Date()) and Date())

, "" Access/Jet. WHERE :

WHERE (results.Date between DateAdd("d", -30, Date()) and Date())

- "", .

, , Jet , . - , ( ), :

WHERE results.Date BETWEEN results.Date-30 AND Date()

, JohnFx DateDiff(), DateAdd .

Jet, , DateAdd() ( "d" ) SQL Server (GetDate ( )), Jet (Date()). Jet/Access SQL, , , "results.Date-30" , DateAdd().

: , , , SQL, , SQL. , ( , , ).

+5

:

SELECT *  
FROM results 
WHERE ([Date] between DateAdd("d", -30, Date()) and Date())

-. "" Access - , , . , [] .

+3

Microsoft Access, (), getdate() ( SQL Server).

+2

. , ?

0

You did not specify SQL Server as your dB. In Access, the syntax is DateAdd: DateAdd ("d", 1, "31-Jan-95").

0
source

Source: https://habr.com/ru/post/1704050/


All Articles