SQL Server 2008 :: Use Folder Name As Database From Batch File To Execute Files

Jul 17, 2015

I've been struggling with this issue,

1) Test--FolderName (This Test folder name should use as a database name for below sub folders)

a)Create--Sub Foldername
i)create.sql
b)Alter---Sub FolderName
i)Alter.sql
c)Insert---Sub FolderName
i)Insert.sql

[Code] .....

The scripts need to be run in order. So script one needs to run first folder in that sub folders after that next second folders etc..

Is there a way to create a bat file that automatically runs all these scripts, in order against, the databases they need to?

The databases that they need to run against have the name of the database at the beginning of the name of the folder.

View 0 Replies


ADVERTISEMENT

SQL Server 2008 :: Running Batch File To Execute A Stored Procedure

May 11, 2015

I have create a batch file to execute a stored proc to import data.

When I run it from the server (Remote Desktop) it works fine, but if I share the folder and try to run it from my pc, it doesn't do anything. I don't get an error, it just doesn't do anything. My windows user has admin rights in SQL. Why is it not executing from my PC?

View 9 Replies View Related

SQL Server 2008 :: Checking Files In A Shared Path If Folder Or File?

Jun 3, 2015

I wrote the below script to print all folders and files located in the share path. How to extend my script to mention by adding another column whether the file is a folder/file , sort of 0 or 1.

declare @chkdirectory1 varchar(4000) = 'shared_pathfolder';
declare @finalserver3 varchar(4000);
create table #tmp (directory_name varchar(4000))
SET @finalserver3 = '''"DIR ' + @chkdirectory1 + ' /B"''';
--select @finalserver3
--SELECT @finalServer
DECLARE @ExecCmd varchar(100)
--SELECT @ExecCmd = 'EXEC master.dbo.xp_cmdshell ' + char(50) + 'mkdir D:'+ CONVERT(varchar(8), getdate(), 112) + '' + char(50)
SET @ExecCmd = 'EXEC master.dbo.xp_cmdshell ' + @finalserver3
--SELECT @ExecCmd
exec(@ExecCmd)
drop table #tmp

View 0 Replies View Related

SQL Server 2008 :: How To Execute Scripts In Batch

Apr 8, 2015

I have separate scripts for Creation of Tables, Stored Procedures, Views, Triggers in different .sql files.

I have to execute thses scripts in batch in different servers and different databases without opening SSMS.

All .sql files to be executed in single command.

View 3 Replies View Related

Execute A Batch File From Within Sql Server

Jul 25, 2001

Hi, and thanks for your help. I have created a simple batch that xcopy files from one directory to another shared directory (in another server). Here is the code:
xcopy c:OUT_TRANSIT E:BACKUP_CESWEB /y

the E:BACKUP_CESWEB is in another server where I mapped the BACKP_CESWEB folder and make it shared.

the location of the batch file is in c:code .
When I double click the batch, the files are moved into E:BACKUP_CESWEB But when I use the window 2000 schedule or try to run the batch code from within sql server analyser, I get no results.

Any idea how to solve this.
The bottom line is that I want to copy files from one server to another server.Thanks for your help

Ali

View 5 Replies View Related

How To Execute A Batch File Using SQL Server 2005?

Dec 23, 2005

Hi all,As the topic describes, I'd like to run a batch file using sql server.How do i do it?Thanks in advance

View 1 Replies View Related

SQL Server 2008 :: SSIS - Package To Zip Contents Of A Folder Into One ZIP File

Aug 12, 2015

I have a requirement to create a package that takes all files in a given folder and adds them to a single archive (.zip) file. I've tried several methods using 7zip and while I can create archives for every file in the directory I can't seem to get them into a single .zip file.

View 9 Replies View Related

OSQL Command - Execute All Files In A Folder;

Aug 8, 2006

Hi,

How do I execute all the .sql scripts in a folder with OSQL command?

Thanks in advance,

Hari Haran Arulmozhi

View 4 Replies View Related

SQL Server 2008 :: Create All Procedures Located In A Folder One By One And Saving Output File

May 15, 2015

I am asked to create 100 procedures to a database. Any best way to create them in a database one by one by calling the files and saving the execution output files in a folder?

View 9 Replies View Related

SQL Server 2008 :: How To Append Hostname / Computername To Text File Using Windows Batch Command

Mar 9, 2015

How to append an hostname/computername to a text file using windows batch command?

View 1 Replies View Related

SQL Server 2012 :: How To Fetch PDF Files From A Folder And Saving It In The Database

Jul 23, 2013

I have a small project to be done in which I need to fetch the pdf file from a my system and save it in database and also fetch the name of it and save it in the database.

View 9 Replies View Related

Execute Batch File

Mar 31, 2000

Hi,
I would like to ask someone who could help me with one small problem:

I would like to run SQL server task on one of my servers, that will connect
to all other servers (including ones that are not SQL servers, ie: Exchange,
Test Server etc) one at the time, and that will execute one batch file (update.bat) that is residing on each server under C: drive.

Batch file will copy some things from all of the servers to one server.

Thanks, in advance.

Regards,
Vilko

View 1 Replies View Related

Execute Batch File As Sql Job

Apr 5, 2006

I'm trying schedule a batch file to run as a job from sql server agent. The batch file copies files from one server directory to a directory on another server. The batch file works properly when executed directly. The job is being executed under the sql service account login. I've given the service account access to both the source and destination directories.

When I try to run the job it fails with an "Access is denied" error on both the source and destination directories (as read from job history).

Any ideas?

View 4 Replies View Related

Execute A Batch File

Jul 25, 2007

Hi All,
I would like to embed some stored procedures in a batch file and execute it from the command prompt on windows.
I have no idea of how to embed a stored proc in a .bat file.
Can you please redirect me to the solution to this?

Thanks in advance
vishu

View 1 Replies View Related

Using Sql To Execute A Batch File

Aug 9, 2007

Is it possible to use sql to execute a batch file? I would like toexecute the following "C:BTWartend.exe /f=C:BTWToolboxFormatscarnum.btw /p", 6Thanks,Matt

View 6 Replies View Related

How To Execute SQL Scripts Using Batch File?

Oct 10, 2007

Hi,How can we execute SQL Scripts using Batch file???i think Batch file should contain Username,Password,Database andScripts...Using that file scripts should run...How can i give UserName,Password,Database and all those things?Plz send me details how to do that...if possible with example...Thanx in advance,RR...

View 2 Replies View Related

Execute Stored Procedure Via Batch File

Jan 20, 2012

I have a stored procedure that generates some data and dumps it into a table. I need to export data using bcp based on the data that this procedure creates. So I know how to use bcp but don't know how to execute the procedure and pass it the two variables that it needs. I googled it and sqlcmd looks promising but can get the syntax right. The two variables are the current year and school number ie. 1112, 0021.

View 3 Replies View Related

How Do I Execute A Batch File From Sqlserver 2000 T-sql?

Nov 6, 2007

I tried the following but file dir.rpt is never created. in fact, the exec statement appears to lock-up forever.


exec xp_cmdshell 'c: empjunkdir.bat'


dir.bat Contains
dir c: > c: empjunkdir.rpt

This should be easy!

View 3 Replies View Related

Ugrent Help: How To Write Code To Execute A Batch File

Apr 15, 1999

hi, I need to run a batch file in specific time of the week. can anyone show me the code to run a batch file with both ways: window nt schedualer and ms sql server task manger.... I do appreciate your help

Ali

View 5 Replies View Related

%1 Is Not A Valid Win32 Application - Trying To Execute A Batch File

Feb 12, 2008

Today I ran into the error (see title of this post) while trying to execute a batch file using SSIS. If anyone else runs into this problem I want to point them to my post on the issue, as I did not easily find a solution when doing the search myself: http://blog.lyalin.com/2008/02/1-is-not-valid-win32-application-ssis.html

Summary (So you dont need to visit my blog):

I was trying to execute a totally empty placeholder batchfile and this produces the "%1 is not a valid win32 application" error when using Execute Process Task. Simply add something to your placeholder file (like DIR command) and you can continue running your package without error

I hope this saves someone time in the future.


Comments? If anything in my post is inaccurate I hope you guys post some corrections.

Regards,

Dmitry
http://blog.lyalin.com

View 1 Replies View Related

Execute Command Process - Remote Batch File?

Feb 23, 2006

Good afternoon-

Can a batch file that resides on another server be executed from a different machine? I have a batch file that resides on a server that I would like to run using SQL 2005 Integration Services. Is there anything I can do that would allow me to remotely execute this batch file and have it run in that environment.

BATCH FILE:

cd C:Trandev
otrun -at OTRecogn.att -DINPUT_FILE=%1 -tl 1 -cs dv -lg mylog -I
C:Trandev represents the remote environment


I have tried mapping the remote machine to a network drive on my local machine and using that drive to execute the batch file in an Execute Process Task, but it does not work.

SSIS:

I have a FOR EACH loop grabbing files and writing fileName to a variable that is passed to the Process Task as an argument through an expression(%1 in the batch file above). The Working Directory is a mapped network drive. The Executable is also a network drive plus batch file name.


Any help would be appreciated.

My computer is a HP Compaq dc7100, 512mb RAM, WindowsXP

View 7 Replies View Related

Calling Remote Batch File Using 'Execute Process Task'

Oct 11, 2006

I have a remote batch file on machine B that I need to execute using 'Execute process task' control from a package on machine A. The batch file uses pgp software and encrypts a file sitting on machine B itself. The reason why my batch file is sitting on machine B, is because the PGP software is on machine B.

If I execute the batch file by itself from machine B, the script runs fine. I refer the same batch file as a UNC path from my package on machine A. But that does not work since the 'Working directory' is still machine A. I can not set machine B's folder as the working dir because it does not accept UNC path. So I say, ok , let me map a path to that UNC location and map it as drive 'Z:'. Certainly if I do so, I will be running the process on machine A and the batch file will look for the pgp software on machine A, and hence fail.

I have tried third party remote batch execution tools (PSEXEC) but have not had success, not because of SSIS limitations, but simply because the PGP executable when run through the PSEXEC tool, does not identify the location of the public keys on machine B and hence gives an encrytion failure.

How do I get the remote batch file to execute such that it executes with its own env? Is there a better remote execution tool I can try or are there any other features of SSIS I can use to get around this issue? I need the results of the batch file and hence do not want to make it an asyncronous process.

Thanks

Sumeet

View 3 Replies View Related

T-SQL (SS2K8) :: Create Batch File To Selectively Run Files

Apr 24, 2014

I have about 1200 sql files in one of my folders. Almost all of these files do data inserts and updates, so they should be run only once. As and when required I have manually ran around 150 of them already. Whenever I ran any of these scripts, I log that file name into a log table in my sql server including the execution time. Since running 1000+ more files takes a lot of time, I want to automate running of these files through a batch file. But I also want to filter the files that are already run.My file list looks like follows.

InsertToOrderTypes.sql
UpdateClientAddress.sql
DeleteDuplicateOrders.sql
InsertToEmailAddress.sql
ConsolidateBrokerData.sql
UpdateInventory.sql
EliminateInvalidOfficeLocations.sql

My log table in the database looks like this.

select * from sqlfileexecutionlog
FileNameRunTimeResult
---------------------
DeleteDuplicateOrders.sql03/12/2014 14:23:45:091Success
UpdateInventory.sql04/06/2014 08:44:17:176Success

Now I want to create a batch file to run the remaining files from my directory to my sql server. I also want to wrap each of these sql file executions in a transaction and log success/failure along with the runtime and filename into sqlfileexecutionlog table. As I add new sql files into this directory, I should be able to run the same batch file and execute only the sql files that have not bee run.

View 9 Replies View Related

Execute A Flatfile Source To Oledb Destination For Each File In A Folder.

Jan 24, 2007

Hello, I wanted to do the following.

Copy a full directory from source to destination (Done)

then for each file on the destination directory,it must process that file and insert rows on the table.

So I created a foreach loop, and created a varriable aclled CURRENTFILENAME, and assigned it into the foreachloop to index 0.



Inside the foreachloop I created a dataflow task, in the dataflow task I dragged a flat file source and an oledb destination, but I noticed that the flat file source requires flat file manager, and the flat file manager requires a unique FILE NAME. I cant put this c:copia*.txt.

I took a loot at flat file source properties and it has associated the flat file manager, but I can not assign the filename to the variable from the foreach.



Any ideas please



View 5 Replies View Related

SQL 2012 :: Calling Remote Batch File Using (Execute Process Task)

Jan 7, 2015

I have a remote batch file on machine B that I need to execute using 'Execute process task' control from a package on machine A.

How Can I achieve this....

View 2 Replies View Related

Fail Execute Process Task Based On Batch File ERRORLEVEL?

Jun 9, 2006

I am new to this, but have scoured the web and not found an answer to my question...

I have an execute process task that runs a simple batch file. When this batch file completes with an ERRORLEVEL greater than 0, I would like the task to fail. I thought this simply meant setting the "FailTaskIfReturnCodeIsNotSuccessValue" property to true, and setting the SuccessValue to 0. However, this does not appear to work.

Even with a simple batch file forcing the errorcode to 1 as follows, the task still completes "successfully".

SET ERRORLEVEL = 1

Any ideas? Thanks!

View 8 Replies View Related

SQL Server 2008 :: Load Latest CSV Files From File Server Automatically

Feb 4, 2015

I need to load the latest csv files from file server , The files are placed in a folder called -

Posted 02022015- --> csv files .

I am able to copy the csv files from filserver using bulk insert (manually) , giving the file location

I am having difficulty picking up the latest folder which is posted on the server and import it into database using a stored proc .

View 2 Replies View Related

SQL Server 2008 :: EXECUTE SP Permissions For Child Database

Feb 19, 2015

I have a database which contains a stored procedure. The stored procedure contains an update script to a different database. The user group have access to the database that stores the stored procedure but do not have update rights to the database that contains the data that is being updated.

Therefore, every time the user group executes the stored procedure it fails because the security permissions do not propagate to the next database.

Is there anything I can do to get around this without grant dbo permissions to the whole user group.

View 2 Replies View Related

SQL Server 2008 :: Automatically Execute Script Once Database Has Been Attached

Jul 29, 2015

our clients have the flexibility to detach and attach databases (I know there are a lot of considerations around this but there is now way of changing it), once they attach a database we need to run some code to update a bunch of values in the database.

Other than creating a SQL Agent job are there any other options available to automatically execute a script once the database has been attached?

View 1 Replies View Related

SQL Server 2008 :: Restore Database From Raw MDF And LDF Files Of Old To New Computer

Aug 18, 2015

I have a client that has POS software called Restaurant Pro Express (RPE) from www.pcamerica.com
Their old POS computer had a hardware failure, but I was able to attach the hard-drive to another computer and recover the data. RPE uses a MSSQL database system. However, my client doesn't seem to make backups very often - the last one is dated January 5, 2015.

I was able to copy the C:Program FilesMicrosoft SQL Server folder over which contained the instance as well as all the data files - and has up-to-date information. The instance in the recovered Microsoft SQL Server folder was called MSSQL.1. I installed the RPE software on their new computer, and it too now has an instance called MSSQL10_50.PCAMERICA. The new computer is using MSSQL 2008 R2, while I believe the old computer would have been using MSSQL 2005.

View 4 Replies View Related

SQL Server 2008 :: Move Database Log Files Massively

Sep 14, 2015

I want to to move all database log files from drive E to F .

There are more than 10 databases so I don’t wanna move them 1 by 1 .

At the moment I use detach – attach method .

-Detach db
-Move log file
-Attach db

How do I do this massively in one go ?

View 5 Replies View Related

SQL Server 2008 :: Copy Multiple CSV Files Into Database Using Stored Procedure?

Feb 9, 2015

I need to import multiple csv files and load into table and everytime new database has to be created .

I was able to create new databases using stored proc

How do i do a bulk insert for all the files at once to insert into tables .

i want to load all the files at once .

View 6 Replies View Related

Passing Parameters To Batch File And Executing Batch File Loop

Aug 7, 2007

HELP,

I need to take a variable from a tabel in SQL Server pass to a Batch file and execute the batch file. Right now I can exec the batch file with XP_CMDSHELL but how can I pass the variable to the batch file and loop through all the variables.

Please help

Phil

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved