How do I output a table to a txt file using tsql? I don't want to use DTS or SSIS in this instance.
+2
A:
bcp MyDb.MySchema.Mytable out myTable.dat -T -c
- out can be replace with queryout if using an sql query, or in if loading data in.
- -T windows authentication, replace with -u and -p for sql auth
- -c outputs as text instead of binary
- -r is the row terminator option
- -t os tje field terminator option
- -S to specify a non default server
thats about all the really usefull options for exporting i think.
Paul Creasey
2010-02-08 23:17:52
+1
A:
Here is the most common answer from a Google search:
EXEC master..xp_cmdshell'bcp "SELECT TOP 5 CUSTOMERID FROM Northwind.dbo.Customers" queryout "c:\text.txt" -c -T -x'
Anthony
2010-02-08 23:19:06
xp_cmdshell, boo! :-)
onupdatecascade
2010-02-09 00:06:47
+3
A:
You can also to press CTRL+SHIFT+F to redirect your SQL Server Management Studio
output to a file.
Rubens Farias
2010-02-08 23:25:33