Wednesday, March 21, 2012

Help with a query

Ive been trying to find out how to write a query like this for months now and feel its time that I get some help :eek:

Im trying to export columns to text files so that they can be accessed via a website to show statistics.
(My SQL database is used for something else and I do not want the website directly connecting to it.)

So first I would have the table ordered by a specific column and then export the top 50 results for example.
I had it working to export to excell but I lost the query :(

Do I use something like EXPORT COLUMNS or INSERT INTO text file sorta thing
ThanksHi Paul

irrespective of the purpose of the db I would have the website access it directly. Why are you unhappy with this?

In any event BCP is an efficient way to get data out of the db and into text files.|||I dont want to lean on the SQL performance and im sure constant connections like this would.

I have never used BCP before so I guess I will go and have a look into that
thanks|||Still no luck BCP is very confusing :S|||is it? it's just a console app. here's how you can export data for an entire table:

bcp MyDatabase.dbo.MyTable out myfile.txt -c -T -SMYSERVER

and here's how to export the result of a query:

bcp "select foo from MyDatabase.dbo.MyTable where bar=12" out myfile.txt -c -T -SMYSERVER

No comments:

Post a Comment