How to loop through files in a specified folder, load one by one from source folder and copy to destination folder using SQL stored procedure.

  • Hi All,

    How to loop through files in a specified folder, load one by one from source folder and copy to destination folder using SQL stored procedure.

    My requirement is, I want to create a SP and which will copy file by file from source folder to destination folder. And before copy I need to check the the file exists in destination folder. If the file is there already so i don't want to copy that file again.

    Please help me on this

    Note: My client doesn't want to use SSIS.

    Regards

    Saratah Babu Vellampalli.

    Kindest Regards,

    Sarath Vellampalli

  • Why would you be required to do this from SQL Server? This is much better handled outside of SQL Server using any number of techniques.

    My preference for something like this would be Robocopy and either a Powershell script or a DOS batch scripts to copy the files from one location to another.

    There are other options...

    If this absolutely must be done with a stored procedure, the only difference to the above options is that you have to enable xp_cmdshell and call out to those batch scripts or execute the commands directly.

    The other option would be to use a SQL Server agent job - and execute the commands using the operating system command system.

    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

  • Sarath Vellampalli (8/27/2011)


    Hi All,

    How to loop through files in a specified folder, load one by one from source folder and copy to destination folder using SQL stored procedure.

    My requirement is, I want to create a SP and which will copy file by file from source folder to destination folder. And before copy I need to check the the file exists in destination folder. If the file is there already so i don't want to copy that file again.

    Please help me on this

    Note: My client doesn't want to use SSIS.

    Regards

    Saratah Babu Vellampalli.

    Lookup "XCOPY" in Windows help. And, no, it won't need to be done from a stored proc. It can be done through a sheduled job.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Just note that XCOPY has been deprecated in Windows Vista and Windows Server 2008 and above.

    The replacement is Robocopy - according to the help if you run XCOPY /? on one of those systems.

    I just checked on my Windows 7 box - and I don't get the deprecated message, which is interesting but I would still recommend Robocopy over XCOPY because of it's greater flexibility.

    If you don't have a copy and are on one of the older OS's, it is included in the Windows Resource Kit for that OS.

    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

  • Yeah, you're right, of course. Old habits die hard.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (8/27/2011)


    Yeah, you're right, of course. Old habits die hard.

    And us old dogs have a much harder time learning new tricks...:w00t:

    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 6 posts - 1 through 5 (of 5 total)

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