Y2K Strikes Again

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/sjones/y2kstrikesagain.asp

  • Steve, you could simplify your WHERE clause with something like this:

    WHERE m.entrydate >= CAST(CONVERT(char, CURRENT_TIMESTAMP, 112) AS datetime)

    AND m.entrydate < CAST(CONVERT(char, CURRENT_TIMESTAMP, 112) AS datetime)+1

    This is more efficient, if you have an index on entrydate column!

    HTH,

    Vyas

    http://vyaskn.tripod.com/


    HTH,
    Vyas
    SQL Server MVP
    http://vyaskn.tripod.com/

  • Thanks, you are right. My quick query was to just match the day month and year, which caused the bug. If I'd gone with yours, I'd never have had an issue.

    course, wouldn't have had an article either.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    http://www.dkranch.net

  • Steve, my WHERE clause would be even simpler, if you just want to see all the notes posted the same day you are running your query:

    WHERE m.entrydate BETWEEN

    CONVERT(datetime, CONVERT(char, GETDATE(), 101)) AND GETDATE()

    This would get all notes submitted between midnight and "right now".

    Hope that helps,

    Julie Liles

  • Steve,

    Great article but, part of it is missing.

    Quote:

    If I check the table, I see

    Unquote

    You see what????

    -SQLBill

  • Ahhh, I think you need your secret decoder ring, SQL Bill.

    something appears to be missing. I'll have to check at home when I get back. Gone for 2 days. In the table I found the entry that was displayed was dated the previous year and there were no entries from the current date.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    http://www.dkranch.net

  • Mmmm. Must admit only done this in testing, mind you I would be happy if this was the only mistake I made, you should see some of my big faux pas', Now I never use the DATEPART abbreviations. Not much help to you now I suppose.

    I am intrigued though when I look at my old code (from years back) and think how poorly written it is or where 'bugs' could creep in (quick fix while no one is looking ).

    I am a great believer in that I learn more from my mistakes than my successes.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Intellisense = Yukon.  We just need hang out a little longer 'til we can catch up with the rest of the development world.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply