From: mcolson on
I am trying to create a stored procedure to write out to a text file.
I would like it to write a line for each instance of a select
statement. Any help?

Write information Where field1 = String
From: Plamen Ratchev on
You can use the BCP utility to output the SELECT statement data to a file:
http://msdn.microsoft.com/en-us/library/aa174646(SQL.80).aspx

Or look at SSIS which may be a better environment for the task:
http://decipherinfosys.wordpress.com/2008/07/23/ssis-exporting-data-to-a-text-file-using-a-package/

--
Plamen Ratchev
http://www.SQLStudio.com
From: Erland Sommarskog on
mcolson (mcolson1590(a)gmail.com) writes:
> I am trying to create a stored procedure to write out to a text file.
> I would like it to write a line for each instance of a select
> statement. Any help?
>
> Write information Where field1 = String

In addition to Plamen's answer: normally you don't write to text files
from SQL at all. You just return data to the client, and the client
would write to the text file. BCP and SSIS that Plamen mentioned are
examples of specialised such clients that are good of extracting lots
of data.
--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx