简体   繁体   中英

SQL Server 2008 - Save each “while loop” result to a different file

I'm using a double while loop to get a lot of results from several different tables. I get everything I need (500+ subjects, each with 1000+ rows), but each comes into a different grid. I would like to save each "while" result to a different .csv file. Is there any way

Might be possible to do using SQLCMD or BCP , but will be quite cumbersome to code, using quite a few variables and dynamic SQL.

If faced with this scenario, I would personally go with an SSIS package -

  1. Use package variables to generate destination filenames dynamically
  2. Use a for each loop container instead of the while loop
  3. Put a dataflow task inside the container and use the Select code as source and the file from step one as the destination

It is pretty easy to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM