SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date and Time help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Chris_Kelley
Yak Posting Veteran

76 Posts

Posted - 08/25/2014 :  12:23:05  Show Profile  Reply with Quote
Hi everyone,

I need to grab all the notes that are from today, and are equal to the current time or 30mins back.

I currently have -

SELECT * FROM NOTE WITH(NOLOCK)
WHERE
NOTE_DATE = SYSDATETIME()
AND NOTE_TIME >= DATEADD(MINUTE, -30, GETDATE())

It returns nothing, I placed the following note in for today

NOTE_DATE NOTE_TIME NOTE_TEXT
2014-08-25 09:13:40.987 09:13:40 NOTE FOR TODAY

any idea why my syntax is not pulling this note?


Thanks,
Chris
Jr Programmer

Chris_Kelley
Yak Posting Veteran

76 Posts

Posted - 08/25/2014 :  12:30:59  Show Profile  Reply with Quote
NOTE_DATE < DATEADD(MINUTE, -30, GETDATE())

GETTING THERE, BUT STILL NOT ALL THE WAY

Thanks,
Chris
Jr Programmer
Go to Top of Page

Chris_Kelley
Yak Posting Veteran

76 Posts

Posted - 08/25/2014 :  12:40:26  Show Profile  Reply with Quote
SELECT * FROM NOTE WITH(NOLOCK)
WHERE
NOTE_DATE > DATEADD(MINUTE, -30, GETDATE())
--AND NOTE_DATE DATEADD(DAY, 0, GETDATE())

OKAY THIS PULLS THE NOTE, BUT I NEED LOGIC THAT WILL ONLY LOOK FOR NOTES THAT WERE ENTERED FOR THE SAME DAY...STILL WORKING ON IT

Thanks,
Chris
Jr Programmer
Go to Top of Page

Chris_Kelley
Yak Posting Veteran

76 Posts

Posted - 08/25/2014 :  12:43:52  Show Profile  Reply with Quote
IDK if this is it, but it seems to work

SELECT * FROM NOTE WITH(NOLOCK)
WHERE
NOTE_DATE > DATEADD(MINUTE, -30, GETDATE())
AND NOTE_DATE >= DATEADD(DAY, -1, GETDATE())

Thanks,
Chris
Jr Programmer
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

394 Posts

Posted - 08/25/2014 :  13:25:41  Show Profile  Reply with Quote
Try this:
SELECT *
  FROM NOTE
 WHERE NOTE_DATE >= DATEADD(MINUTE, -30, GETDATE())
   AND NOTE_DATE < GETDATE()
   AND NOTE_DATE > CAST(GETDATE() AS DATE)

quote:
Originally posted by Chris_Kelley

SELECT * FROM NOTE WITH(NOLOCK)
WHERE
NOTE_DATE > DATEADD(MINUTE, -30, GETDATE())
AND NOTE_DATE >= DATEADD(DAY, -1, GETDATE())
Go to Top of Page

Chris_Kelley
Yak Posting Veteran

76 Posts

Posted - 08/25/2014 :  14:12:46  Show Profile  Reply with Quote
quote:
Originally posted by bitsmed

Try this:
SELECT *
  FROM NOTE
 WHERE NOTE_DATE >= DATEADD(MINUTE, -30, GETDATE())
   AND NOTE_DATE < GETDATE()
   AND NOTE_DATE > CAST(GETDATE() AS DATE)

quote:
Originally posted by Chris_Kelley

SELECT * FROM NOTE WITH(NOLOCK)
WHERE
NOTE_DATE > DATEADD(MINUTE, -30, GETDATE())
AND NOTE_DATE >= DATEADD(DAY, -1, GETDATE())





Awesome, thank you so much, works perfect! TY TY

Thanks,
Chris
Jr Programmer
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000