Sqlcmd to generate file without dashed line under header, without row count

后端 未结 8 1758
难免孤独
难免孤独 2021-02-01 06:09

Using the following sqlcmd script:

sqlcmd -S . -d MyDb -E -s, -W -Q \"select account,rptmonth, thename from theTable\"  
> c:\\dataExport.csv
<
8条回答
  •  离开以前
    2021-02-01 06:50

    In addition, if you want to query out all records in a table, you can code as

    1. SET NOCOUNT ON;
    2. SELECT SUBSTRING((SELECT ','+ COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=N'%table_name%' FOR XML PATH('') ), 2, 9999);
    3. SELECT * FROM %table_name%

    Assign the above queries into a variable %query%. The the command will be looks like as below.

    SQLCMD -h -1 -W -E -S %sql_server% -d %sql_dabase% -Q %query% -s"," -o output_file.csv
    

提交回复
热议问题