By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Need help writing a stored procedure

P: n/a
How would I write a stored procedure to get * where duedate is less
than and not equal to today's date. Is this right?

select * from library
where duedate < != getdate()

Thanks
Feb 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You would write it like this:

select * from library
where duedate < getdate()

However, since GETDATE() returns the current date and time, there are
chances you will get duedate values for today, those between midnight and
the current time. The correct way is to reset the current time portion to
midnight. You will end up with something like this:

SELECT <columns>
FROM Library
WHERE duedate < DATEADD(day, DATEDIFF(day, '20010101', CURRENT_TIMESTAMP),
'20010101')

In the above formula the time portion is trimmed by simple arithmetic:
calculating the difference in days between a preset date (Jan-1-2001) and
today, and then adding back the number of days to the same date. Since the
DATEDIFF returns the number of days only, the time portion is discarded.

And CURRENT_TIMESTAMP is just the ANSI SQL equivalent to GETDATE().

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Feb 2 '08 #2

P: n/a
select * from library
where duedate < getdate()

--

Jack Vamvas
___________________________________
Search IT jobs from multiple sources- http://www.ITjobfeed.com


"JJ297" <nc***@yahoo.comwrote in message
news:11**********************************@s8g2000p rg.googlegroups.com...
How would I write a stored procedure to get * where duedate is less
than and not equal to today's date. Is this right?

select * from library
where duedate < != getdate()

Thanks

Feb 4 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.