Insert date

  • i need to write insert where the date column , takes automatically from the system

    and laods the data

    instead of putting the date in the insert script everyday

    i need to schedule this daily

    insert into table name

    select * from databse name .table name

    where convert(varchar,datedate, 101) = '01/25/2010'

    instead of me putting me the date in here , i want it to be automaticaaly generated

  • For that you need to specify each column names instead of * and then at the date field use the custom date, something like below

    insert into desttable (col1,col2,date,col4)

    select

    col1,col2,convert(varchar,getdate(),101),col4 from sourcetable

    HTH...

    The_SQL_DBA
    MCTS

    "Quality is never an accident; it is always the result of high intention, sincere effort, intelligent direction and skillful execution; it represents the wise choice of many alternatives."

  • To select data based upon today's date, you can do the following:

    SELECT {columns}

    FROM {table}

    WHERE YourDateColumn >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)

    AND YourDateColumn < DATEADD(day, DATEDIFF(day, 0, GETDATE()) + 1, 0);

    This assumes that you have dates in the future and only want to pull today's data. If you do not have dates in the future remove the second line in the where clause.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 3 posts - 1 through 2 (of 2 total)

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