Arguments:
-U login_id
Is the user login ID. Login IDs are case-sensitive.
-P password
Is a user-specified password.
If the -P option is not used, osql prompts for a password.
If the -P option is used at the end of the command prompt without any password,
osql uses the default password (NULL).
-S server_name[\instance_name]
Specifies the instance of Microsoft® SQL Server™ 2000 to connect to.
Specify server_name to connect to the default instance of SQL Server on that server.
Specify server_name\instance_name to connect to a named instance of SQL Server 2000 on that server.
If no server is specified, osql connects to the default instance of SQL Server on the local computer.
This option is required when executing osql from a remote computer on the network.
-q "query"
Executes a query when osql starts, but does not exit osql when the query completes.
(Note that the query statement should not include GO).
If you issue a query from a batch file, use %variables, or environment %variables%.
For example:
SET table = sysobjects
osql /q "Select * from %table%"
Use double quotation marks around the query and single quotation marks around anything embedded in the query.
-Q "query"
Executes a query and immediately exits osql.
Use double quotation marks around the query and single quotation marks around anything embedded in the query.
-o output_file
Identifies the file that receives output from osql.
The greater than (>) comparison operator can be used in place of -o.
If input_file is not Unicode and -u is not specified, output_file is stored in OEM format.
If input_file is Unicode or -u is specified, output_file is stored in Unicode format.
If output_file only specifies a file name, osql creates a file with that name in the current folder.
To place the file in another folder, specify the path to that folder in output_file,
such as –o C:\MyFolder\MyReport.rpt.
-w column_width
Allows the user to set the screen width for output. The default is 80 characters.
When an output line has reached its maximum screen width, it is broken into multiple lines.
Example syntax:
osql /U sa /P password /d pubs /S Server9 /Q "Select * from Authors"
osql /U sa /P password /d pubs /S Server9 /Q "sp_help"
osql /U sa /P password /d pubs /S Server9 /Q "sp_help" -o ofile.txt
set mysqlcommand=sp_help
osql /U sa /P password /d pubs /S Server9 /Q "%mysqlcommand%"
* * * * * * * * * * * *
Example for script in using file .bat:
1. Save this file below using name, example: "_checking_Script.vbs"
------------------------------------------------------------------------------
OPTION EXPLICIT
dim objFSO, objoutputFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objoutputFile = objFSO.CreateTextFile("_bat_checking_Script_1.bat")
objoutputFile.writeline "osql -S Server1 -U sa -P sasasa -d pubs -Q ""EXEC _sp_task_check_1 '1234569', '012'"" -o Results-task-check.rpt -w 60000"
objoutputFile.close
------------------------------------------------------------------------------
2. Double-click for file "_checking_Script.vbs"
3. In same folder will create file "_bat_checking_Script_1.bat"
4. To get the results, double-click file "_bat_checking_Script_1.bat"
5. Then you can get the results file in format .rpt, you can open this file using wordpad (optional).
Sumber:
http://msdn.microsoft.com/en-us/library/aa214012%28v=sql.80%29.aspx
http://www.sqlteam.com/article/osql-storing-result-of-a-stored-procedure-in-a-file