How to get output from SQLCMD or OSQL?

792 Views Asked by At

Looked everywhere... to no avail.

I am trying to do a basic select using SQLCMD from the command line:

sqlcmd -S myServer -d myDB -E

So far so good.

select * from myTable

Nothing, just goes to the next line. Shouldn't it display a table with values ? Or at least "n row(s) returned" ?

I also tried the -o param: it creates an empty file.

1

There are 1 best solutions below

0
jpw On

When you use the SQLCMD tool in interactive mode statements that you enter are sent to the server when you use the keyword GO.

GO signals both the end of a batch and the execution of any cached Transact-SQL statements. When specifying a value for count, the cached statements will be executed count times, as a single batch.

See Use the sqlcmd Utility specifically the section titled Running Transact-SQL Statements Interactively by Using sqlcmd

So in your case:

select * from myTable enter

GOenter