Tuesday, March 20, 2012

save results to multiple files

I have a table with hundreds of thousands of records. I don't want to
get into why, however I need to take all this data and save it to file.
Now I can do this fine with Query Analyzer saving to file, however
every 15,000 records I need to continue writing to the "next" file. Is
there a way to do this through SQL Server should I write something
quick in Java or something to do this?
Thanks.
JRosql is easiest to write results to a file.
osql -E -i c:\query.qry -o c:\test.txt
-E is the integrated security switch or you can use -U sa -P password
-i is for an input file (Create a text file with the query in the path you
put into osql)
-o is for the output file that the query results are sent
Let me know how it works for you. I tested this with a result set of 75,000
rows, but have never tried with more than that.
"JR" wrote:

> I have a table with hundreds of thousands of records. I don't want to
> get into why, however I need to take all this data and save it to file.
> Now I can do this fine with Query Analyzer saving to file, however
> every 15,000 records I need to continue writing to the "next" file. Is
> there a way to do this through SQL Server should I write something
> quick in Java or something to do this?
> Thanks.
> JR
>|||Thanks for the reply. As I mentioned before, I can use Query Analyzer
to do this with hundreds of thousands of records. I want to be able to
split the output based on file size or number of records to limit the
size of the text file.
Derekman wrote:
> osql is easiest to write results to a file.
> osql -E -i c:\query.qry -o c:\test.txt
> -E is the integrated security switch or you can use -U sa -P password
> -i is for an input file (Create a text file with the query in the path you
> put into osql)
> -o is for the output file that the query results are sent
> Let me know how it works for you. I tested this with a result set of 75,00
0
> rows, but have never tried with more than that.
> "JR" wrote:
>|||Use osql in a batch file to create different result files based on the numbe
r
of returned rows in the select statement. If there is an identity column in
the result set this will make it easier. You can use VBscript or JScript if
need be to create the variables to pass back to a query file and increment
the output file.
"JR" wrote:

> Thanks for the reply. As I mentioned before, I can use Query Analyzer
> to do this with hundreds of thousands of records. I want to be able to
> split the output based on file size or number of records to limit the
> size of the text file.
> Derekman wrote:
>

No comments:

Post a Comment