Search notes:

SQL Server: sqlcmd - colon commands - :out

:out filename specifies the name of a file into which the result of select statements (or print statements) are redirected.
set nocount on

:out export.txt

select foo, bar from baz;
go

:out stdout

See also

colon commands

Index