SQL Server 2000 using OSQL via .bat file issues...

  • I am attempting to use and schedule a .bat file that utilizes OSQL. The application folks say they will create different file names based on a process for import... Is it possible to have an OSQL statement pull in ANY .sql file.... I cannot find if it is even possible...

    This is what I have used...

    OSQL -U dhuserid -P dhpass -S server2000 -d dh_db -i E:\nessus.sql -o E:\daveout.log -n

    He states that the nessus.sql file may be this... or nssus1, 2, 3, 4... etc have no way of knowing ahead of time... I tried *.sql and nss*.sql but it won't accept it.

    Any help is appreciated.

  • you could pull all the file names into a temp table by calling the dos command dir through xp_cmdshell, after you have the file name in the table set up a loop to build the osql string and again run that trough xp_cmdshell.

     

    Here is a link that may point you in the right direction:

     

    http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=150

  • I do understand that you are trying to run OSQL from a dos script.

    I would query the directory, dynamically compose OSQL line and then run. I would do it from VBscript using filesystemobject. For example, I am getting all CSV files for my application into a list of files as save this list as a file. It is very easy in VB to append strings before and after the file name. Then we will have a file of the OSQL statements for each sql file in the directory. Then we save this file as mylist.bat some time before the scheduled job executing this file runs.

     

    Regards,Yelena Varsha

  • Try the old DOS For command

    for %f in (n*.sql) do OSQL -U dhuserid -P dhpass -S server2000 -d dh_db -i %f -o %f.log -n

  • I tested it, it works! Good Job David!

    They say in Russia that " NEW is a well forgotten OLD "

     

    Regards,Yelena Varsha

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

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