A requirement has been arisen to export large SQL tables into a cloud storage. Nowadays, there are many ETL tools and cloud services in the market that support this process. However, in this particular scenario, the requirement was to develop a custom proc to export a given table into multiple CSV files based on a batch size (i.e. specific number of rows per file)
Following proc generates a dynamic BCP command and then execute it using xp_cmdshell system proc.
e.g. Call procedure - TSQL
e.g. Call procedure - PowerShell