BCP export with unique file

  • When i export with bcp to a *.csv file i get a non unique filename.

    Example: myNativeFile.csv.

    I like to get a date in my filename. Does anybody know a good method for this?

    Maybe i kan design two scripts.

    1. myNativeFile.csv for the import in Oracle (unicode)

    2. myNativeFile20110209.csv for the archive

  • I advise using SSIS. You can set up filenames using expressions in SSIS and make it repeatable.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • You can use variables in dynamic SQL. Here's a snippet:

    SET @Cmd = 'BCP "SELECT * FROM ' + DB_NAME() + '.dbo.MyTable" queryout "' + @Folder + @FileName + @Extension + '" /c /T '

    PRINT ' Executing xp_cmdshell: ' + CONVERT(varchar(1000), @Cmd)

    EXEC master..xp_cmdshell @Cmd

  • Thanks guys, i will have a look at both solutions.

  • An additional note about SSIS, you can multicast the same data to do different destinations at the same time. That's one of the reasons why I like it for situations like this.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

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

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