I have this simple little batch file program that I wrote but it fails if I enter a database name that contains a "-" character. Im not exactly sure why but I wish I could figure out a way around this?
:: open DB batch file
@echo off
:: starts Sql Server Management Studio Express 2005
:: and opens it to a specific database with query
:: window already open
cls
:SHOWDBNAMES
echo Database names detected on this system:
echo.
"%PROGRAMFILES%\Microsoft SQL Server\90\Tools\Binn\OSQL.EXE" -h-1 -S . -E -Q "SELECT CAST(name AS VARCHAR(30)) FROM sysdatabases"
@echo.
set DBNAME=
set /P DBNAME=What database name would you like to open (choose from list)?
if "%DBNAME%" == "" (
echo.
echo I don't recognize your selection. Try again.
goto SELECTDB
)
:SHOWTABLES
cls
echo.
echo Tables that you can query from %DBNAME% are:
echo.
"%PROGRAMFILES%\Microsoft SQL Server\90\Tools\Binn\OSQL.EXE" -h-1 -S . -E -Q "use [%DBNAME%];SELECT CAST(name AS VARCHAR(30)) FROM sys.Tables ORDER BY name"
echo.
:RUNIT
sqlwb.exe -nosplash -S . -E -d %DBNAME%
pause
:EOF