karinos57
asked on
pull last 2 days of data (excluding today's data)
Hi,
How can i pull the last 2 days of data excluding today's data? I have a column that has a timestamp like this:
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:28.000
2012-01-02 00:04:28.000
2012-01-02 00:04:28.000
How can i pull the last 2 days of data excluding today's data? I have a column that has a timestamp like this:
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:16.000
2012-01-02 00:04:28.000
2012-01-02 00:04:28.000
2012-01-02 00:04:28.000
ASKER
jogos:
this is what i get when i run it:
Operand type clash: date is incompatible with int
this is what i get when i run it:
Operand type clash: date is incompatible with int
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or staying in same datatype but getting rid off the timestamp from GETDATE()
DECLARE @today as DATETIME
SET @todaty = CAST(FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME)
select * from dbo.yourtable
where yourdate >= @today - 2
and yourdate < [u][/u]@today
ASKER
works like a charm
set @today = getdate();
select * from dbo.yourtable
where yourdate between @today - 2 and @today