Date change

  • Hello,

    I'm currently using psloglist to export some security logs to csv format then importing them into a sql 2005 database.

    Use Apr09

    bulk INSERT Ramses

    FROM 'G:\Ramses Logs\20090420-Ramsesapp.csv'

    WITH

    (

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = ''

    )

    How can I make a query that will pull the date field YYYYMMDD in the above query instead of typing it in everyday?

  • amdavis (4/20/2009)


    Hello,

    I'm currently using psloglist to export some security logs to csv format then importing them into a sql 2005 database.

    Use Apr09

    bulk INSERT Ramses

    FROM 'G:\Ramses Logs\20090420-Ramsesapp.csv'

    WITH

    (

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = ''

    )

    How can I make a query that will pull the date field YYYYMMDD in the above query instead of typing it in everyday?

    Not sure if this will work for you, but how about:

    Use Apr09

    bulk INSERT Ramses

    FROM 'G:\Ramses Logs\' + CONVERT(VARCHAR,GETDATE(),112) + '-Ramsesapp.csv'

    WITH

    (

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = ''

    )

  • what happened when I ran it...

    Msg 102, Level 15, State 1, Line 2

    Incorrect syntax near '+'.

    Msg 319, Level 15, State 1, Line 3

    Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

  • You will need to use dynamic SQL:

    Use Apr09;

    Declare @bulk_cmd varchar(1000);

    Set @bulk_cmd = 'BULK INSERT Ramses

    FROM ''G:\Ramses Logs\''' + CONVERT(VARCHAR,GETDATE(),112) + '-Ramsesapp.csv''

    WITH

    (

    FIELDTERMINATOR = ''',''',

    ROWTERMINATOR = '''')'

    Execute(@bulk_cmd);

    Make sure you match up the quotes correctly - I did not test the above.

    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 4 posts - 1 through 3 (of 3 total)

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