The sqlcmd utility can allow you to connect to an MSSQL database from the command line and run queries against it.