0 votes
1 view
in SQL by (20.3k points)

I am looking for a good SQL Statement to select all rows from the previous day from one table. The table holds one datetime column. I am using SQL Server 2005.

1 Answer

0 votes
by (40.4k points)

Use this code to get today no time:

SELECT dateadd(day,datediff(day,0,GETDATE()),0)

To get yesterday no time, use this query:

SELECT dateadd(day,datediff(day,1,GETDATE()),0)

Query for all of rows from only yesterday try this:

select 

    * 

    from yourTable

    WHERE YourDate >= dateadd(day,datediff(day,1,GETDATE()),0)

        AND YourDate < dateadd(day,datediff(day,0,GETDATE()),0)

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...