スカラーデータベースクエリを実行し、その結果をバッチファイルの変数に戻したいとします。スカラークエリの結果をバッチファイル変数に戻す
どうすればよいですか?スカラークエリの結果に基づいて終了コードを返す場合、私が見る私のシステムで最も近い私の例です。
Z:\SQL2005\90\Tools\Binn\sqlcmd -S servername -dCLASS -E -Q "EXIT(select case run_type when 'Q' then 200 else 100 end from cycle_date where cycle = '1')">NUL
if %errorlevel% == 200 call %SQLSERVER%
QRTLY.BAT
if %errorlevel% == 100 call %SQLSERVER%
MTHLY.BAT
構文を教えてもらえますか?
-v var = value[ var=value...]
Creates a sqlcmdscripting variable that can be used in a sqlcmd script. Enclose the value in quotation marks if the value contains spaces. You can specify multiple var="values" values. If there are errors in any of the values specified, sqlcmd generates an error message and then exits.
sqlcmd -v MyVar1=something MyVar2="some thing"
sqlcmd -v MyVar1=something -v MyVar2="some thing"
-x disable variable substitution
Causes sqlcmd to ignore scripting variables. This is useful when a script contains many INSERT statements that may contain strings that have the same format as regular variables, such as $(variable_name).
あなたの答えはよさそうです。ちょうど1つのフォローアップの質問:私は、SET sqlcmd = "C:¥Program Files¥Microsoft SQL Server¥100¥Tools¥Binn¥sqlcmd.exe"のように、sqlcmdへのパスを完全修飾することを躊躇します。 、 "ファイル名、ディレクトリ名、またはボリュームラベルの構文が間違っています。" – ChadD
変更点は次のとおりです。FOR/F "usebackqトークン= 1" %% i IN( '%sqlcmd%-S%サーバー%-d%db%-w200 -h-1 -E -Q" REPORTING_DATE FROM dbo.CURRENT_REPORTING_DATE "')DO設定REPORTING_DATE = %% i – ChadD
http://stackoverflow.com/questions/6860897/issue-executing-an-exe-when-the-path-has-spaces – ChadD