Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output to a Text file

Status
Not open for further replies.

DrSql

Programmer
Jul 16, 2000
615
US
Is there any way that I can get the output of a select statement in a text file.

[tt]
Select EmpId,Fname,Lname, SSN, Dept from employee
[/tt]
The results need to be a C:\OutPut\emprec.txt


Dr.Sql
Good Luck.
 
You don't say how you are running the query...if you use Query Analyzer, go to Tools>Options then to Results tab. You can change the output there.

-SQLBill

Posting advice: FAQ481-4875
 
Sorry.. I want to schedule to run daily.
Its part a stored procedure.

Dr.Sql
Good Luck.
 
If you can run the job from the system prompt (command line) there's an old DOS trick that will work:

c:\process.bat>C:\OutPut\emprec.txt

Note the '>'. It redirects results away from the screen and dumps them into the file specified. > will create or overwrite, >> will create or append.

hth.
 
Any suggestions other than BCP. I prefer some SQL syntax

Dr.Sql
Good Luck.
 
I'm not sure I understand what you mean by you Prefer some SQL syntax. If you don't want BCP then you can create a dts package to do what you want.

Shoot Me! Shoot Me NOW!!!
- Daffy Duck
 
This can also be done by a SQL job which can be scheduled. Create a TSQL step with the select statement containing the required command. go to the advanced tab and change the "output" field to your required file. Then define a schedule. It could also be done by a DTS package.
 
Thanks guys.. But I was looking any SQL syntax rather than DTS, Command (BCP).I guess there is nothing like that in SQL. I used to a Synatx in Oracle way back, I was think SQL might have something. May be in 2005.

Dr.Sql
Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top