Forum Discussion

Victor_Sotnikov's avatar
Victor_Sotnikov
Copper Contributor
Aug 18, 2025
Solved

Can a T-SQL procedure copy content of an Excel sheet to another Excel-файл?

Is it possible to create a T-SQL procedure that would do the following:

  1. Open an input Excel-файл; locate a specific sheet there;
  2. Open an output Excel-файл; locate a specific sheet there;
  3. Copy the whole content of the input file sheet into the output file sheetю

?

  • Hi Victor_Sotnikov​ unfortunately, No — this cannot be done purely in T-SQL. SQL Server is designed for database operations and does not provide native commands to manipulate Excel files at the sheet level.

    You can perform all these steps using 

    PowerShell + SQL:

    Use PowerShell scripts to:
    1. Open input Excel, copy sheet content to output Excel (with Import-Excel / Export-Excel modules, or COM Interop).
    2. Optionally call that script from SQL Agent if you want it tied to a SQL job.

    or

    ETL Job / SSIS (SQL Server Integration Services):
    ETL tool that can import/export between Excel files and SQL, and can also transfer between Excel files.

     

    Please change the status to resolved if you are satisfied with the answer.

1 Reply

  • pradejain's avatar
    pradejain
    Iron Contributor

    Hi Victor_Sotnikov​ unfortunately, No — this cannot be done purely in T-SQL. SQL Server is designed for database operations and does not provide native commands to manipulate Excel files at the sheet level.

    You can perform all these steps using 

    PowerShell + SQL:

    Use PowerShell scripts to:
    1. Open input Excel, copy sheet content to output Excel (with Import-Excel / Export-Excel modules, or COM Interop).
    2. Optionally call that script from SQL Agent if you want it tied to a SQL job.

    or

    ETL Job / SSIS (SQL Server Integration Services):
    ETL tool that can import/export between Excel files and SQL, and can also transfer between Excel files.

     

    Please change the status to resolved if you are satisfied with the answer.

Resources