Write a SQL batch file to generate CSV in a particular location - sql-server

I have been able to create csv file with the following sql cmd:
sqlcmd -S servername -d test_database -E -Q "select * from test_database.dbo.product" -s "," -o "C:\Users\Ron\Desktop\Example.txt"
but my intention is to make this bat file run as a task scheduler in order to run it everyday at particular time and at a same time, since we are generating the folder every day basis, we need the file name should follow date month year format in the naming convention with the CSV extension and it should not be overrided.
Summary:I need to generate the CSV files with the different naming convention at particular location in our server by running task scheduler which will invoke that bat file everyday at particular time. Do we need to change the bat file command to change the name of folder (I would like to give the name by date basis as it will be generated in every day and help me to track those files).
I have been able to create csv file with the following sql cmd:
sqlcmd -S servername -d test_database -E -Q "select * from test_database.dbo.product" -s "," -o "C:\Users\Ron\Desktop\Example.txt"
but unable to find out particular command which will help us to reach out to our goal.

Related

batch file - sqlcmd failing in scheduled tasks (0x2331)

I'm trying to use scheduled tasks to run a database back up once per day using sqlcmd that points to a SQL script.
If I open a command prompt and run the code in the batch file everything is successful but when task manager tries it gets a 0x2331 error.
A search reveals it's something to do with permissions - maybe I need to change the path to the sql file?
here is the script:
ECHO OFF
ECHO This is running to backup a database
sqlcmd -S COMPNAME -i C:\backup.sql
GO
ECHO Success!
EXIT
I'm new to batch files to tried to keep it as simple as possble.

Open Sql Script with big size

I have an SQL script file which it has big size " 1.4 GB "
when I try to open it in SQL SERVER Management Studio
it fails and give me message
The System can't find the file specified
when I try to open it with notepad++
file is too big to be opened by notepad++
so does it there anyway to open this script ?
Run this command in Command prompt by providing the required details. This command would execute the SQL file without opening the file.
sqlcmd -S <ServerName> -U <LoginUser> -P <Password> -d <DatabaseName> -i <Inputfilenamewithpath> -o <Outputfilenamewithpath>

How do I create a batch file from Advantage SQL script?

I have created sql script using SQL Utility within Advantage Data Architect of Sybase. The script is saved on my workstation. Now, how do I create a batch file that would run the script from desktop?
I found this command line online, but it doesn't seem to be working:
#echo on
isql -U "username" -P "password" -S "servername" -D "database" -i "path"
#echo off
I am new to Advantage SQL, trying to learn as much as I can.
Thanks.
You use adssqlcmd.exe, passing the connection and script name as command-line parameters. There is an example of doing so on that second page:
rem Using the connection path option, and process the script files
rem after making the connection.
rem The program will terminate after processing all files
asqlcmd.exe -S ALS:d:\mydata\main.add -U user1 -P sample -i myscript.sql
There's a list of supported commands that outline what you can and can't do in the script as well.
Also note that adssqlcmd.exe is a feature added in ADS v11, and is not available to earlier versions of ADS.

Batch file to run JMeter script

I have a .jmx file of all of my test plans and I want to create a batch file. When I click that, everything starts and ends automatically. So that I can provide it to my client as well to verify that I have performed the load test on his website. How can I achieve this?
jmeter does not support running batch of .jmx files as document part 2.4.3 (Command Line Mode) gives to us.
I would recommend you to try 2 approaches:
1) to follow best practices of running jMeter in non GUI mode.
In accordance to this approach you are expected to use the command
jmeter -n -t D:\TestScripts\script.jmx -l D:\TestScripts\scriptresults.jtl
Where the pareameters:
-n [This specifies JMeter is to run in non-gui mode]
-t [name of JMX file that contains the Test Plan]
-l [name of JTL file to log sample results to]
-j [name of JMeter run log file]
2) to use any cloud service for running your .jmx file.
BlazeMeter (http://blazemeter.com/) worked for me fine.
One can adjust the test plan settings.
Testing results can be seen on “Load Report” tab as soon as test finishes.
For detalization one can follow Getting Started: Scripting with JMeter steps.
Hope this works for you.
Just write the following command in a text file and save this file as SomeName.bat
#ECHO OFF
jmeter -n -t "Your .jmx file path" -l "Your .jtl file path"
For example:
#echo off
jmeter -n -t F:\DEV\WORKSPACE\buyer.jmx -l F:\DEV\WORKSPACE\output.jtl
After saving click on that bat file. The test plan result will be stored into .jtl file.
Note: Make sure you put this bat file into JmeterinstallationDirectory/bin folder.

Create Sh and Bin File to Execute all SQL Scripts in folder

I'm not sure if this is possible, but if I have a directory with 40+ SQL Scripts in it. Is it possible to make a run_scripts.bat and/or a run_scripts.sh file to execute all SQL scripts in the folder? Sorry I don't have even a start code, but I've been looking around at how this would be done to no avail. Thanks to anyone that can help
Depending on the database you use (e.g. mysql), you can just run in a loop:
for f; do
mysql -u $DBUSER -p $DB <$f
done
Then, you can call this on the command line:
$ sh run_scripts.sh *.sql

Resources