March 25, 2014 at 4:14 pm
Out Table has date as '2014-04-25' and time as 12:00 AM , 1:01 Am ,12:10 pm etc....
I need to see records for last two hours ...
How should I do so?
March 25, 2014 at 4:31 pm
With the little data you have posted ... use Books on Line and check the use of the BETWEEN statement
From Books on Line:
test_expression BETWEEN begin_expression AND end_expression
March 25, 2014 at 4:32 pm
You will need to use DATEADD as well.
March 25, 2014 at 5:15 pm
sharonsql2013 (3/25/2014)
Out Table has date as '2014-04-25' and time as 12:00 AM , 1:01 Am ,12:10 pm etc....I need to see records for last two hours ...
How should I do so?
select
*
from
YourTable
where
datecolumn between dateadd(hour,-2,getdate()) and getdate();
March 26, 2014 at 5:59 am
sharonsql2013 (3/25/2014)
Out Table has date as '2014-04-25' and time as 12:00 AM , 1:01 Am ,12:10 pm etc....I need to see records for last two hours ...
How should I do so?
Does this mean you have two columns?
What is the data type of the column(s)?
March 26, 2014 at 9:52 am
Let me be a little bit more clear on that...
There are two columns
CurrentDate Date,
Time Varchar(10)
If I do , Select * from Data
Order By Date Desc , Time Desc shows the following results
The result is :
2014-03-26 3:01 AM
2014-03-26 2:01 PM
2014-03-26 2:01 AM
2014-03-26 12:01 PM
2014-03-26 12:01 AM
2014-03-26 11:01 AM *********** Shouldn't this be on top of :01 am?
I need to see the latest Date and Time in an order... If I resolve this I will be able to resolve my issue.
March 26, 2014 at 10:04 am
You can combine the two thus
SELECT CAST(CurrentDate AS DATETIME) + CAST(Time AS DATETIME) FROM Data
This will be a DATETIME value. So you might use a CTE to combine the values then do the compare
March 26, 2014 at 10:54 am
Thanks . That helps.
March 26, 2014 at 11:45 am
If you would like some real help solving your problem please read the following article. It will show you what you need to post and how to post it to get the best possible responses to your question. Remember, we can't see what you see so you need to help us help you.
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply