开发者

TSQL QUERY to dump table into a file

开发者 https://www.devze.com 2023-04-03 15:46 出处:网络
i have tried the following command to write a text file from a table: EXEC master..xp_cmdshell \'bcp \"SELECT * FROM DB.dbo.table1\" queryout \"C:\\employee.txt\" -T -Sservername -U user111 -P pwd

i have tried the following command to write a text file from a table:


    EXEC master..xp_cmdshell 'bcp "SELECT * FROM DB.dbo.table1" queryout "C:\employee.txt" -T -Sservername -U user111 -P pwd -c -t,'

No file is created, I am not sure why. Can anyone pls help?

I am not getting errors instead I get following messages:

usage: bcp {dbtable | query} {in | out | queryout | format} datafile [-m maxerrors] [-f formatfile] [-e errfile] [-n native type] [-c character type] [-w wide character type] [-N keep non-text native] [-V file format version] [-q quoted identifier] [-C code page specifier] [-t field terminator] [-r row terminator] [-i inputfile] [-o outfile] [-a packetsize] [-S server name] [-U username] [-P password] [-T trusted connection] [-v开发者_如何学运维 version] [-R regional enable] [-k keep null values] [-E keep identity values] NULL


Try creating a temp directory and add this to your path. It could well be Windows protecting the root of the drive.

EXEC master..xp_cmdshell 'bcp "SELECT * FROM DB.dbo.table1" queryout "C:\TempDir\employee.txt" -T -Sservername -U user111 -P pwd -c -t,' 

If the above statement works, then it is a permissions issue.


the query was correct -

EXEC master..xp_cmdshell 'bcp "SELECT * FROM DB.dbo.table1" queryout "C:\employee.txt" -Sservername -U user111 -P pwd -c -t,'

while typing in SQL SERVER MANAGEMENT studio I pressed enter after queryout so statement "C:\employee.txt" -Sservername -U user111 -P pwd -c -t,' was coming in next line. because of this I was not getting any error or output file

0

精彩评论

暂无评论...
验证码 换一张
取 消