2

This might be a stupid question but I am learning about SQLCMD and the code for it. I don't really understand where to put the statement in.

This is what I am suppose to do. Use SQLCMD to output the results of the query SELECT COUNT(*) FROM Customers to the console window.

I have never done this before so I am thrown off a little. If someone would be able to help me understand it that would be great. I have done web searches and reviewed my book but it doesnt say where you will type the code into and I am working with SQL server 2008.

1
  • With the command prompt is that what you click start then accessories then to the command prompt and code it in there? Commented Nov 7, 2011 at 17:22

2 Answers 2

3

I think the best way to show how it is used is with documentation. You can see the SQLCMD Reference here.

You use sqlcmd to execute Transact-SQL against an instance\database.

This is untested, but your example your desired command would be something like: sqlcmd -U <yourLogin> -Q "select count(*) from Customers" -S <yourMachineName>\<yourInstanceName>

After you hit "ENTER", you will be prompted for your password (this is provided you are using SQL Auth), and then upon authentication you will see the result of your query on the console window.

Sign up to request clarification or add additional context in comments.

Comments

0
C:\Program Files\Microsoft SQL Server\110\Tools\Binn>sqlcmd -Q "use YourDB"
 C:\Program Files\Microsoft SQL Server\110\Tools\Binn>sqlcmd -Q "Select * From YourDB.dbo.param1"
id          num
----------- -----------
          3           1
          2           2
          3           3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.