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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BCP Copy works from command line but not batch file when using LIKE

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hello. I am trying to run the following BCP script:

Code:
c:\binn\bcp "select script from backupdatabases..backupscript where dbname like 'a%'" queryout e:\mssql2000\mssql\backup\backupscripts\backupA.txt -S servername -U username -P password -c

If I type this manually from the command line it runs perfectly and exports 5 lines to the resulting text file.

If I run as a batch file, I pretty much get the bcp /? window that shows the usage and all of the switches.

As a side note. The batch file works great if I change [LIKE 'A%'] TO [= 'ADAMS']. The script seems to fail when using LIKE and a % wildcard.

I also tried putting the database directly after the c:\binn\bcp:

Code:
c:\binn\bcp backupdatabases "select script from backupscript where dbname like 'a%'" queryout e:\mssql2000\mssql\backup\backupscripts\backupA.txt -S servername -U username -P password -c

If I run as a batch file I get the same bcp /? window. If I run directly in command line I get an error: "Copy direction must be either 'in', 'out', or 'format.'

Any idea what is different in a batch file vs typing directly into command line where it won't use the LIKE clause?

Thanks!
 
Because this is a batch file, you need to double the % symbols.

Code:
c:\binn\bcp "select script from backupdatabases..backupscript where dbname like 'a[!]%%[/!]'" queryout e:\mssql2000\mssql\backup\backupscripts\backupA.txt -S servername -U username -P password -c

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top