Removing rows from a table

  • I need to remove all rows from a table based on the date value being at lease sixty days old from the update date (i.e. today). The syntax needs to be part of a table update job.

    What's the syntax to tell it to remove x number of rows. Does it start with 'Update Table' or 'Alter Table Alter column', etc.

    I'm not really sure.

    thx,

    John

  • latingntlman (8/5/2008)


    I need to remove all rows from a table based on the date value being at lease sixty days old from the update date (i.e. today). The syntax needs to be part of a table update job.

    What's the syntax to tell it to remove x number of rows. Does it start with 'Update Table' or 'Alter Table Alter column', etc.

    I'm not really sure.

    thx,

    John

    It starts with delete.

    something like:

    delete from mytable where datatimeColumnThatHasTheDateofUpdate< dateadd(day, -60, getdate())

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • thx,

    Now I need to convert getdate() as 2008-08-06 00:00:00

    What's the best syntax I can use?

    JOhn

  • latingntlman (8/5/2008)


    thx,

    Now I need to convert getdate() as 2008-08-06 00:00:00

    What's the best syntax I can use?

    JOhn

    If you want a datetime then:

    select DATEADD(Day, 0, DATEDIFF(Day, 0, getdate()))

    if you want a varchar without the milliseconds then:

    select convert(varchar(40), DATEADD(Day, 0, DATEDIFF(Day, 0, getdate())), 20)

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

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

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