Change evaluate a column based on time?

  • Hi

    Here is how I would do.

    the expression : dateadd(dd, 0, datediff(dd, 0, <Colum in DATETIME Format)) actually returns the the date part of the column with the time set to 00:00:00

    eg dateadd(dd, 0, datediff(dd, 0, '2008-03-06 14:36:52.823')) returns '2008-03-06 00:00:00'

    SELECT CASE

    WHEN dateadd(dd, 0, datediff(dd, 0, )) = dateadd(dd, 0, datediff(dd, 0, GETDATE() )) THEN 1

    ELSE 0

    END AS DateFlag

  • Sorry, I may not have explained myself correctly. This change needs to be carried out automatically on the fly as the 0 or 1 value controls part of a ETL.

  • This post is strange because it does not have a question at the beginning.

    I need to be able to set a flag from 0 to 1 when the datetime field within the same table is equal to today's date.

    Does this mean you want to actually update table data? If so, you could do an update like this:

    UPDATE MYTABLE

    SET Flg = 1

    WHERE Flg = 0 AND

    CONVERT(VARCHAR,MYDATECOLUMN,101) = CONVERT(VARCHAR,GETDATE(),101)

  • somehow I posted above the previous post.... :hehe:

  • Hi All,

    I need to be able to set a flag from 0 to 1 when the datetime field within the same table is equal to today's date.

    What is the best way to implement this?

    Thanks

Viewing 5 posts - 1 through 4 (of 4 total)

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