0

I have the query

EXEC xp_cmdshell 'bcp "select * from foo.dbo.bar" QUERYOUT "c:\temp\export.csv" -c -t, -T -S'

Which exports fine to that file, but is it possible to break it down so that the first 1000 rows go into export.csv then the next 1000 rows go into export2.csv (etc etc)

bummi
  • 27,123
  • 14
  • 62
  • 101
franglais
  • 928
  • 2
  • 15
  • 39
  • http://stackoverflow.com/a/972074/3983442 Would that work for you? – Stephen Oct 14 '14 at 14:44
  • @Stephen Not really - I don't want to have to run the command 450 times changing the limit each time :D I was hoping I could run one command that would be able to break it down for me! – franglais Oct 14 '14 at 14:46
  • 1
    Try this one: http://stackoverflow.com/questions/17632236/exporting-sql-server-table-to-multiple-part-files – Andrew Oct 14 '14 at 15:02
  • @Andrew That would probably work, although I actually did what someone else suggested in that thread and do the full export then split it using a tool called CSV File Chunker which seems to have done the trick! – franglais Oct 14 '14 at 15:13
  • If you have to do this repeatedly, you might want to look at SSIS. – Ann L. Oct 14 '14 at 17:32

0 Answers0