views:

34

answers:

1

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,
+3  A: 

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

The same switch can be used for sqlcmd too

gbn
That is the answer but it still leaves a huge blank footer of whitespace after the result. Any way to trim that?
djangofan
@djangofan: yes, you need to CAST to varchar because you actually have xml datatype output. Sorry, I can't test right now, you'll have to play around a bit, perhap use a derived table or CTE
gbn
ok, thanks. i got it: SELECT CAST(name AS VARCHAR(30)) FROM sysdatabases
djangofan