increment values on day basis on column

  • dwain.c (8/29/2012)


    Had to make a slight correction to my prior post and add a question.

    -- casting GETDATE as INT gives different results before and after midday

    SELECT

    CAST(GETDATE() AS INT),

    GETDATE() - 0.2, -- 08:14

    GETDATE() + 0.2,-- 17:50

    CAST(GETDATE() - 0.2 AS INT), -- 41148

    CAST(GETDATE() + 0.2 AS INT) -- 41149

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • ChrisM@Work (8/29/2012)


    dwain.c (8/29/2012)


    Had to make a slight correction to my prior post and add a question.

    -- casting GETDATE as INT gives different results before and after midday

    SELECT

    CAST(GETDATE() AS INT),

    GETDATE() - 0.2, -- 08:14

    GETDATE() + 0.2,-- 17:50

    CAST(GETDATE() - 0.2 AS INT), -- 41148

    CAST(GETDATE() + 0.2 AS INT) -- 41149

    So are you saying the CAST is rounding? How annoying!


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (8/29/2012)


    ChrisM@Work (8/29/2012)


    dwain.c (8/29/2012)


    Had to make a slight correction to my prior post and add a question.

    -- casting GETDATE as INT gives different results before and after midday

    SELECT

    CAST(GETDATE() AS INT),

    GETDATE() - 0.2, -- 08:14

    GETDATE() + 0.2,-- 17:50

    CAST(GETDATE() - 0.2 AS INT), -- 41148

    CAST(GETDATE() + 0.2 AS INT) -- 41149

    So are you saying the CAST is rounding? How annoying!

    Isn't it!

    SELECT CAST(GETDATE() AS FLOAT)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 3 posts - 16 through 17 (of 17 total)

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