Forum Discussion
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:
- Open an input Excel-файл; locate a specific sheet there;
- Open an output Excel-файл; locate a specific sheet there;
- 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
- pradejainIron 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.