[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

MSSQL - Select data from now to yesterday at a specific hour

Posted on 2014-02-08
3
Medium Priority
?
1,060 Views
Last Modified: 2014-02-08
I have a table (SQLJobStatus) with a column (Job_Date) that has date/time records.  (2014-02-07 23:30:00.000)

I am trying to get all records from last night at 11:30pm  (23:30:00) until now.

select * from SQLJobStatus where ((Job_Date >= (DATEADD(d,-1,GETDATE()))) and ((convert(varchar, job_date, 108) >= '23:30:00')))

I tried this query however, I only get yesterday jobs from 23:30.  The >= on selecting the date is only giving me yesterday.  I see that is caused by the time portion being selected as > 23:30 which would only select the jobs on the next date that were greater than this.

Not sure how to write the correct syntax.

Would appreciate help writing a clean query to give me all records as needed.

Thanks
0
Comment
Question by:rsmith1969
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39844737
Something like this perhaps:

SELECT  *
FROM    SQLJobStatus
WHERE   Job_Date >= DATEADD(minute, 1410, DATEADD(DAY, -1, DATEDIFF(DAY, 0, GETDATE())))

Open in new window

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 total points
ID: 39844740
This might be a tad clearer:
SELECT  *
FROM    SQLJobStatus
WHERE   Job_Date >= DATEADD(minute, 1410, DATEDIFF(day, 1, GETDATE()))

Open in new window

0
 

Author Comment

by:rsmith1969
ID: 39844741
Thanks...  For some reason I couldn't wrap by head around this... I kept running into a roadblock.  Looks like I need to research datedff.

Now any time I run my program it will give me all of the jobs from last night instead of the last 6 hours.

Thanks again....
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question