question

dpushkar avatar image
dpushkar asked

how can save querry in text file,

xp_cmdshell'bcp "select top 5 * from sw_tokenDeletion"c:\TestMail\ filename.txt" -c -U sa -P temp123 -S (172.25.11.20)' Sir It is showing result usage: bcp {dbtable | query} {in | out | queryout | format} datafile [-m maxerrors] [-f formatfile] [-e errfile] [-F firstrow] [-L lastrow] [-b batchsize] [-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] [-h "load hints"] [-x generate xml format file] NULL (12 row(s) affected) Sir pls reply soon .........................(`_`)
sql-serverbcpdata-exportquery-out
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Usman Butt avatar image
Usman Butt answered
It is correctly suggested. You should have seek more help from local/online BOL. Try this EXEC xp_cmdshell 'bcp "select top 5 * from sw_tokenDeletion" queryout "c:\ TestMailfilename.txt" -c -U sa -P temp123 -S 172.25.11.20' Two things to be noted 1. You need to specify `queryout` keyword when you are copying data from a query 2. There should not be brackets around the Server IP/NAME Hope it helps.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.