Stored Procedure to change filename

  • Hi, Newbie here, have 2 questions. I dont want to use C or other programs just stored procedure, in SQL Server 2005...

    Q1. I want to write a stored procedure to change the filename. The file currently comes to the server that includes the timestamp.

    For example: The file lands on

    E:\Folder1\Filename_yyyymmdd_hhmmss.txt

    and I want it to be renamed to

    E:\Folder1\Filename_yyyymmdd.txt

    Q2.

    The text file has a pipe delimited first row header that is something like "HEADER|yyyymmdd|nnrows"

    Can I copy the yyyymmdd from the header row to the filename? using the Stored procedure

    Thanks

    Dan

  • dan_g (5/18/2012)


    Q1. I want to write a stored procedure to change the filename. The file currently comes to the server that includes the timestamp.

    For example: The file lands on

    E:\Folder1\Filename_yyyymmdd_hhmmss.txt

    and I want it to be renamed to

    E:\Folder1\Filename_yyyymmdd.txt

    Yes, you can use xp_cmdshell to issue windows command prompt command such as 'ren'.

    dan_g (5/18/2012)


    Q2.

    The text file has a pipe delimited first row header that is something like "HEADER|yyyymmdd|nnrows"

    Can I copy the yyyymmdd from the header row to the filename? using the Stored procedure

    You can issue a bulkinsert command or openrowset for just that first header record and store in a variable. Then in question 1 you use that variable value in the command being issued to rename the file.

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

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