The fact that the data in the SQL Server table is exported conditionally to multiple Excel files is what we want to introduce in this article, in a SQL Server database operation, you need to export a table with hundreds of thousands of rows of data to an XLS file by category, one XLS per category. It is easy to export data from a datasheet and save it as XLS, and save it as an SSIS or query. However, there are hundreds of categories in this table, and if you save it as a separate SSIS or query, the workload is huge. Other, think of a while loop query, and the method exported by bcp.
The following are the relevant code:
--use xp_ Cmdshell system stored procedures perform patchwork statements (you need to use advanced option switches to open Cmdshell components beforehand) exec master. xp_cmdshell @sql --Gets the ID of the next category (the category ID is discontinuous) Select @TypeID =isnull (min (typeid), @TypeID + 1) from t_testtable where typeid>= @TypeID +1 End |
The above is the SQL Server table data by conditional batch export to multiple Excel file implementation method, this article is introduced here, I hope this introduction can be harvested for you!