Home Forums SQL Server 2005 Development Output a sql resultset to csv automatically with sql job RE: Output a sql resultset to csv automatically with sql job

  • Yes, you need to supply your login information when using SQLCMD. Here is a sample from something I have done recently.

    sqlcmd -S\Dbserver -U sa -P password1 -s, -W -i c:\apinvoice.sql

    This would run the contents of the apinvoice.sql file.

    Here are the contents of that file:

    use CheckProcess

    SET NOCOUNT ON

    GO

    select * from ap_invoice

    :out E:\Imaging\Admin\SQLFiles\Invoices.csv

    GO

    This created a file with the contents