Create a bcp command line.


Then you can make it dynamically.


Here is an example...


(can be run from query analyzer or made part of a stored procedure)


declare @bcpcmdline nvarchar(4000)
declare @sqlfilename varchar(100)


select @sqlfilename = '\\myserver\mydirectory\myfilename.txt'

select @BCPCMDLINE = 'bcp "select rec_id, employee_name from '
  + ' Employee_table order by employee_name" queryout '
  + @SQLFILENAME
  + ' -S ' + @@servername + ' -T -t, -c'

EXEC MASTER..XP_CMDSHELL @BCPCMDLINE, NO_OUTPUT


What this will do is query the employee_table for rec_id and employee name
and save it as a comma delimited file using a trusted connection.


You should be able to find out more information of the switches.


Also note that it is very easy to modify the @bcpcmdline variable to do what
you need dynamically.


Steve

-----Original Message-----
From: Scott Weikert [mailto:[EMAIL PROTECTED]
Sent: Monday, November 10, 2003 3:45 AM
To: CF-Talk
Subject: RE: Getting CF to trigger a SQL data export to text file

At 07:19 PM 11/9/2003, you wrote:
>Create a DTS in MS SQL
>Execute the DTS from the Command line.

That sounds fine if you were going to export the same data from the same
table every time - but I need to be able to vary what table, and what
fields within that table, that gets exported. If one has to do part of the
setup manually, it won't work for my needs, I fear.

  _____  


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to