Data in SQL tables exports multiple Excel files conditionally

Source: Internet
Author: User
Tags min ssis

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.