Here is the code I have so far:
DECLARE @bcpCommand varchar(2000)
DECLARE @query varchar(2000)
SET @query = 'select job_description from [mainDB].[myschema].[table]'
SET @bcpCommand = 'bcp " ' + @query + ' " queryout "c:\test.csv" -T -c -t,'''
EXEC master..xp_cmdshell @bcpCommand
When I run this, I get the following message:
NULL
Starting copy…
1000 rows successfully bulk-copied to host-file.
Total received: 1000 1000 rows successfully bulk-copied to host-file.
Total received: 2000 1000 rows successfully bulk-copied to host-file.
Total received: 3000 1000 rows successfully bulk-copied to host-file.
Total received: 4000 1000 rows successfully bulk-copied to host-file.
Total received: 5000 1000 rows successfully bulk-copied to host-file.
Total received: 6000
6564 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 16 Average : (410250.00
rows per sec.)
The file doesn’t exist in the c drive though. Why doesn’t the file show up in the c drive? Am I looking at the wrong place?
This will output to the C drive of the server, not the client machine. Is it possible you’re looking at your C drive and not the server’s?