sql-serversql-server-2005osql

How to get results from OSQL.exe without dash characters from the command line?


Is there a way to send a osql query from the command line that returns results that do not include the big long line of dash characters that represent the column width?

Here is the sample code I am working with:

echo.
"%PROGRAMFILES%\Microsoft SQL Server\%SQLVER%\Tools\BINN\osql" -S . -E -Q "SELECT name + ', ' FROM sysdatabases order by name for XML PATH('')"

And the results look something like this:

 -------------------------------------------------------------------------------------------------------------------------------------------

        ------------------------------------------------------------------------------------------------------------------------------------

        ------------------------------------------------------------------------------------------------------------------------------------

        ------------------------------------------------------------------------------------------------------------------------------------

        ------------------------------------------------------------------------------------------------------------------------------------
 master, model, msdb, openfire, tempdb,

Solution

  • Use -h-1 switch to suppress headers: the dashes are the header/data separator "line"

    The same switch can be used for sqlcmd too