SQLCMD & Batch File

  • Hi,

    I am using SQLCMD in a batch file.

    I am unable to do the following thing

    I have to pass the address path in the following line.

    sqlcmd -E -i "%1\File.sql" -o "%1\Log\File.txt"

    Also please take care that the batch file should run by double clicking and so the path address from where it is called must be passed to the %1 menitoned in the SQLCMD code.

  • passing parameters is not possible if you want to execute the batch file by double clicking it.

    Alternatevely, to get the current directory use the %CD% variable. This is how you can use it::

    SET currentdirectory=%CD%

    Now use %currentdirectory% instead of %1 in your code wherever you want the value of current directory.

    -Vikas Bindra

  • Dear Vikas,

    Before reading your posting I tried with %~dp0 replacing %1/ and it worked fine. Today I will try with your stuff also Thanks for reply Vikas...

  • Looks like %~dp0 is also an option to get the working directory. Thanks for updating me on this!!

    The only difference I found is the leading '\' in case of %~dp0.

    -Vikas Bindra

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply