csv bulk insert with variables

  • Use database1

    declare @date varchar(100) = (select Convert(VarChar, GetDate(), 112))

    Declare @fullpath varchar(100) = 'c:\templogs\'+(@date)+'-server1.csv'

    bulk INSERT server1 FROM '+@fullpath+'

    WITH

    (

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = ''

    )

    How do I say from 'c:\templogs\20100323-server1.csv' using the declared @fullpath?

    The file name changes everyday because of the date change and I'd like to automate it.

    Help!

  • Use dynamic SQL. See:

    sp_executesql and

    Using sp_executesql

  • If this is an everyday (or at least very regular) process, I would highly suggest taking the opportunity to learn and use SSIS.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

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

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