Dump db to CSV


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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AneeshDatabase ConsultantCommented:
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
exec master..cmdShell 'bcp mydb.dbo.UrTable out sales.csv /U /P /Ssales_svr /c /t'
drtesterAuthor Commented:
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!
AneeshDatabase ConsultantCommented:
What is the authentication method you are using ? Windows or mixed ?
U have to put your username immediately after the /U and ur password after /P.
For example If you are using sql authentication with username 'sa' and password 'pass', the above procedure can be modified as

exec master..cmdShell 'bcp Test.dbo.Sales out c:\sales.csv /U sa /P pass /S LocalHost  /c /t'

this will create the result csv in c:\
I don't have much idea on ASP.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.