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

后端 未结 8 1923
难免孤独
难免孤独 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:46

    I used another solution to solve the issue of removing the dashed line below the header.

    DECLARE @combinedString VARCHAR(MAX);
    
    SELECT @combinedString = COALESCE(@combinedString + '|', '') + COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME  = 'YOUR_TABLE_NAME'
    

    Then just use Print @combinedString above your select statement. I used pipe delimiter.

提交回复
热议问题