March 21, 2008 at 10:19 am
Hi,
I would like to save the output to my local coputer from a SELECT query of a table of a database in the remote server, how can I specify the path "myLocalComputerPath" in the following script?
use NorthWind
exec master..xp_cmdshell 'bcp "select * from NorthWind..Customers" queryout "myLocalComputerPath\Customers.txt" -T -c'
The database is on a remote server. I would like the output text file is saved on my local computer.
Thank in advance.
johnsql
April 7, 2008 at 8:37 am
You have to grant the SQL Server service account appropriate permissions in the folder on your local machine and use the UNC name in the query.
E.g. (untested):
Assuming the UNC share name on your local machine is "myLocalComputerPath" and the name of your machine is "myLocalComputer":
use NorthWind
exec master..xp_cmdshell 'bcp "select * from NorthWind..Customers" queryout "\\myLocalComputer\myLocalComputerPath\Customers.txt" -T -c'
ML
---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com
April 7, 2008 at 9:11 am
Or - execute the DTS package from DTSRUN or DTSRUNUI on the local machine. By running from a local user and under the correct security context, you'd have access to saving the output locally.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply