Link to home
Start Free TrialLog in
Avatar of drtester
drtester

asked on

Dump db to CSV

Hello,

I'm a total newbie for the MS platform, and just inherited a Windows 2000 webserver running an app that uses the MS SQL server.

I want to write a simple little script that when I hit it with a browser request, it will dump a given table to me in comma separated format (no matter how many columns there are).  Is there a simple way to do this with an .aspx file?
Avatar of Aneesh
Aneesh
Flag of Canada image

u can use the bop command to export to the csv file


bcp mydb.dbo.UrTable out sales.csv /U /P /Ssales_svr /c /t

Inorder to call this from an aspx page, u need to write a procedure containing this statement
CREATE PROC ExprtExcel
AS
exec master..cmdShell 'bcp mydb.dbo.UrTable out sales.csv /U /P /Ssales_svr /c /t'
go
Avatar of drtester
drtester

ASKER

Ok, so let's say my database is called "test", and the table I want to export is called "sales".  The SQL server is running on the localhost.  What code would I put in an asp file to make this happen?  I could go with either rendering the .csv in the browser, or having it actually create a file within the public web space.  THanks!
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial