Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sqlcmd input file

Status
Not open for further replies.

R7Dave

Programmer
Oct 31, 2007
181
US
Hello - I am trying to use sqlcmd in a BAT file.

Could someone help me out by letting me know why my input parameter doesn't work - below are my steps.

FileA.bat works, FileB.bat does not.

FileA.bat

Code:
sqlcmd -S (local) -d DBA -Q"DBCC ShowContig With TableResults,ALL_Indexes" -o"C:\Folder\OutputFile.txt"

FileB.bat

Code:
sqlcmd -E -S (local)  -d DBA -i "C:\Folder\InputFile.sql"
-o"C:\Folder\OutputFile.txt"


FileA.bat returns the results of the query, FileB.bat does not.

- contents of C:\Folder\InputFile.sql

Code:
DBCC ShowContig With TableResults,ALL_Indexes

The difference between FileA & FileB is that FileA uses Q- and FileB uses i-

How can I get FileB.bat to work with -i?

Thanks in advance
Dave


 
Remove quotes before name of the file.
Code:
sqlcmd -E -S (local) -d DBA -i C:\Folder\InputFile.sql -o"C:\Folder\OutputFile.txt"


Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Thanks, but that didn't work

I tried...

Code:
sqlcmd -E -S (local)  -d DBA -i C:\Folder\InputFile.sql
-o C:\Folder\OutputFile.txt"

and

Code:
sqlcmd -E -S (local)  -d DBA -i C:\Folder\InputFile.sql
-o C:\Folder\OutputFile.txt

Thanks
Dave

 
Strange!!!
It worked for me.
BTW maybe it works with quotes also, but when I tested it I deleted InputFile beforehand and forgot about it :)


Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Do you happen to have a new line in FileB.bat? In your original post, it certainly appears as though you do? With the carriage return in there, the command prompt is interpreting this as a second command to execute instead of a continuation of the first command (the SQLCMD part).

Basically, I'm suggesting that you open the bat file in notepad and make sure everything is on one line.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
GMMASTROS - thank you - that worked!

Thank you to Borislav also.

I looked into so many other things before posting - and learned, which is great and all....

Thank you again.
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top