SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



SQLCMD & Batch File Expand / Collapse
Author
Message
Posted Wednesday, January 14, 2009 2:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 22, 2009 5:16 AM
Points: 3, Visits: 10
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.
Post #636057
Posted Wednesday, January 14, 2009 2:23 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, March 17, 2010 4:17 AM
Points: 473, Visits: 836
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
Post #636065
Posted Wednesday, January 14, 2009 9:03 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 22, 2009 5:16 AM
Points: 3, Visits: 10
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...
Post #636805
Posted Thursday, January 15, 2009 12:06 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, March 17, 2010 4:17 AM
Points: 473, Visits: 836
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
Post #636865
« Prev Topic | Next Topic »


Permissions Expand / Collapse