Bulk insert and extra column RRS feed

  • Question

  • DECLARE @Transdate DATETIME ='20100203'
        DELETE tblPFOF WHERE Tradedate = @Transdate
        DECLARE @sql1 VARCHAR(1000)   
        SELECT @sql1 = '
        FROM ''\\server1\Incoming\pfof.txt''
        with (FIRSTROW = 3, FIELDTERMINATOR=''    '', ROWTERMINATOR = '''+CHAR(10)+''')'

        EXEC (@sql1)

    This is piece of code in a procedure which uses bulk insert and working properly.
    When I added a extra column called lastModified to the table it fails.
    I want to update the current time(same time for all rows) to each row when i inserting into the table.

    Some thing like

    DECLARE @Now DateTime = GETDATE()

    I want to add @Now to it. How can i do this?

    Thursday, March 11, 2010 10:50 PM

All replies

  • set default value for date field and then you don't need to insert for date field

    alter table mytable
    add create_date datetime default getdate()

    if date field is already in the table then set its default value to getdate()

    Thursday, March 11, 2010 10:52 PM
  • still it fails.
    Thursday, March 11, 2010 11:19 PM
  • what u mean failed?
    Thursday, March 11, 2010 11:27 PM
  • Hi,

    Could you please try to clarify how you  add @Now parameter? And what is the error you got? Do you convert the date type before adding?

    Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, March 16, 2010 5:41 AM