I have a data set of a 1m+ records. I need to output the query to multiple files depending on a order by .
Example Data set:
ID StoreName StoreChain MoreData........
1 walmart NY Walmart ...
2 Walmarty NJ Walmart ....
3 Target NY Target ....
4 Costco NY Costco ....
Example Query
Select StoreName, SotreChain,moreData order by StoreName
I need to write for each store name. (4 files)
Select StoreName, StoreChain,moreData order by StoreChain
I need to write a file for each Chain, (3 files)
Today I use a CLR SP, it works fine but is a little slow (1h for 1000 files of 200-400 lines each)
I want to know if there is a pure T-SQL solution, if needed it can use the command shell.
and it has to write to a log table every time it creates a file.