[dba-SQLServer] Output to Text File

Shamil Salakhetdinov shamil at users.mns.ru
Tue Jul 13 03:06:56 CDT 2004


Christopher,

You can use bcp - here is a sample(watch line wraps) of one step T-SQL
job:

-- dropping temp table
if exists (select * from tempdb.dbo.sysobjects where name = '##T1')
   drop table [dbo].[##T1]
go
-- creating temp table
CREATE TABLE ##T1 ( column_1 int, column_2 nvarchar(30))
INSERT ##T1 VALUES (1, 'Row #1')
INSERT ##T1 VALUES (2, 'Row #2')
INSERT ##T1 VALUES (3, 'Row #3')
go
-- bcp-ing temp table data
master..xp_cmdshell 'bcp ##T1 out
d:\temp\export\temp_T1.txt -c -C850 -SYOUR_SERVER_NAME -T'
go

HTH,
Shamil

----- Original Message ----- 
From: "Mackin, Christopher" <CMackin at Quiznos.com>
To: <dba-sqlserver at databaseadvisors.com>
Sent: Tuesday, July 13, 2004 3:36 AM
Subject: [dba-SQLServer] Output to Text File


> Hi,
>
> I have a daily fixed width text file that I need to produce and I am
currently generating it via VBA code, but am trying to post it to a SQL
Job.  I have it set up to output to the proper file, the problem is that
at the top of the file there is header info that I need to eliminate.
It looks like the following:
>
> Job 'VPP' : Step 1, 'Create File' : Began Executing 2114-17-12
17:31:31
>
> OutputLine
> ----------------------------------------------------------------------
----------
>   813             212111132122111119987 111446349317132114
>   813             212111132122111119988 111619832817132114
>
> Starting with the 813 is the data that I need in there, everything
above needs to go, does anyone know how to do this?
>
> Also, what other methods are people using to generate Text files from
T-SQL?
>
> Thanks,
> Chris Mackin
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>




More information about the dba-SQLServer mailing list