June 21, 2012 at 4:15 am
Hi Guys,
just a quick one, I'm extracting data to a CSV for an accounts reconciliation and really would like the extract part of it to be coded in the stored proc instead of using SSIS as I think SSIS will add more complexity than is required.
I know there is bulk insert for importing data, is there a similarly nice and simple way of outputting data to csv?
Cheers,
Ben
^ Thats me!
----------------------------------------
01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
----------------------------------------
June 21, 2012 at 4:18 am
BCP would be an option
June 21, 2012 at 4:25 am
awesome thanks that looks good.
should be able to run that through xp_cmdshell with a trusted connection.
Ben
^ Thats me!
----------------------------------------
01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
----------------------------------------
June 21, 2012 at 6:15 am
another option is this suite of CLR export functions I created and put on codePlex as a proof-of-concept:
https://sqlclrexport.codeplex.com/
here's the example code of exporting a table to a CSV report:
EXECUTE CLR_ExportTableToCSV @TableName = 'Products',
@FilePath = 'C:\Data',
@FileName = 'Products_export.csv',
@IncludeHeaders = 1
or a query:
EXECUTE CLR_ExportQueryToCSV @QueryCommand = 'SELECT * FROM Products',
@FilePath = 'C:\Data',
@FileName = '\Products_export.csv',
@IncludeHeaders = 1
Lowell
June 21, 2012 at 6:18 am
Thanks Lowell, one to add to the tool repository, will take a look at them.
June 22, 2012 at 1:21 pm
BenWard (6/21/2012)
Hi Guys,just a quick one, I'm extracting data to a CSV for an accounts reconciliation and really would like the extract part of it to be coded in the stored proc instead of using SSIS as I think SSIS will add more complexity than is required.
I know there is bulk insert for importing data, is there a similarly nice and simple way of outputting data to csv?
Cheers,
Maybe a new BULK EXPORT command to go along with the existing BULK INSERT command. Wouldn't that be nice?
SQL Engine - BULK EXPORT command
Note the resolution status 😀
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
June 22, 2012 at 5:14 pm
opc.three (6/22/2012)
BenWard (6/21/2012)
Hi Guys,just a quick one, I'm extracting data to a CSV for an accounts reconciliation and really would like the extract part of it to be coded in the stored proc instead of using SSIS as I think SSIS will add more complexity than is required.
I know there is bulk insert for importing data, is there a similarly nice and simple way of outputting data to csv?
Cheers,
Maybe a new BULK EXPORT command to go along with the existing BULK INSERT command. Wouldn't that be nice?
SQL Engine - BULK EXPORT command
Note the resolution status 😀
You must be doing research for an xp_CmdShell article. 🙂
I'm amazed at Microsoft. They take the time to give us "improvements" like PIVOT but no time to actually do something that people really want. That CONNECT items has a lot of +'s on it.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply