Questions tagged [osql]

a command-line utility that allows users to execute Transact-SQL (TSQL) statements and scripts.

The osql utility is a command-line utiilty that allowers users to execute Transact-SQL statements and scripts, with the results either returned to the command prompt, or a text file if specified.

For more information, including switches, see the MSDN documentation or enter osql /? in the command prompt.

56 questions
1
vote
0 answers

SQL Server 2017 - Quickest way to write query results to an XML file

I'm trying to find the quickest way to output XML results to disk from within SQL Server. This needs to be automated and quick as there are thousands of records to process. These are the options that I am aware of: sp_OACreate & sp_OAMethod…
LeSteelBox
  • 395
  • 2
  • 13
1
vote
1 answer

SQLCmd Password parameter with comma

We have a SQL server for which the password contains comma (','). Since we use the same in SQLCmd, the process fails. Please find the query which we are using below SQLCmd -U%1 -P%2 /S%servername% /dDbName -Q"EXEC sp_test null, 'DbName',…
1
vote
2 answers

Error using osql.exe (Sql Server 2005)

I use sql server 2005 enterprise, windows server 2003. I try execute osql.exe command, for execute sql file in my server DESSQL: osql.exe -E -n-1 -i"CarpetaUno\TextFile1.sql" I get this error: Msg 102, Level 15, State 1, Server DESSQL, Line…
Kiquenet
  • 13,271
  • 31
  • 133
  • 232
1
vote
3 answers

Using osql with nant scripts

I am currently using osql with nant by calling a batch file with arguments. Here are the properties that are defined in my nant script (no, not real username/password values):
Jamie Wright
  • 1,152
  • 10
  • 22
1
vote
1 answer

Executing SQL Script using OSQL do not return resultcode

I am executing some sql queries using OSQL through inno setup. I am using following code to run OSQL. This is just for example purpose SQLQuery:= '"EXEC sp_addserver ''PCNAME'';"'; Param:= '-S(local) -Usa -Psa -Q ' + SQLQuery; Exec('osql.exe',…
Newbee
  • 1,239
  • 1
  • 16
  • 34
1
vote
1 answer

osql -S not giving me expected results

I'm trying to write a program in Java that uses osql to generate a list of databases on a server. My code is as follows: public Object[] findDataBases(String server, String user, String passwd){ str = new String[] {"cmd.exe", "/c", "osql", "…
chama
  • 5,537
  • 13
  • 57
  • 72
1
vote
1 answer

what cmd command I can use ANSI formatting for my OSQL output text file?

I am running OSQL command in .bat file and I am running my SQL script and generating the output in a text file, however the data in the file is scattered and I want to generate the file in the same format as i can generate via SQL Server manually. I…
1
vote
2 answers

Help on getting started with powershell - rewrite an old BAT + SQL file

I'm totally new to powershell, and I need some help to get started. What I need is to write a small script that backup a SQL database, but every time with different name (to keep the last 4-5 versions only). Right now I have a BAT, which just launch…
bzamfir
  • 4,328
  • 10
  • 51
  • 85
1
vote
1 answer

Generating a .csv file by running a .sql script with osql.exe

I have a script file in a folder.I want to use TSQL to run this script without opening it in SSMS as I will be using SSIS to run this script to generate CSV. I have used OSQL to achieve this by using Execute Process Task but it is not giving me…
user1757018
  • 35
  • 2
  • 7
1
vote
3 answers

osql vs Invoke-Sqlcmd-- redirecting output of the latter

We're moving from a batch file that calls osql to a Powershell script which uses the Invoke-Sqlcmd cmdlet. Would anyone know what the equivalent steps are for redirecting the output in the latter case, to using the -o flag in osql? We have some…
larryq
  • 13,813
  • 35
  • 107
  • 181
0
votes
3 answers

BCP / sqlcmd / osql with encapsulated text fields?

Can any of these command line tools export to .csv like: "int_field", "varchar_field", "another_int_field" 10, "some text", 10 5, "more text", 1 etc? i don't want to use a view or stored procedure to hack the double quotes in :)
Lee Tickett
  • 5,475
  • 8
  • 29
  • 51
0
votes
0 answers

OSQL script file Execution Error

I have a script file (actually a series of them..) which when opened in Query Analyzer, and executed works perfectly. When I execute it via the OSQL command, it fails saying it can't find a DB that I know exists... Yet when I execute the same…
Mike D
  • 149
  • 1
  • 1
  • 13
0
votes
1 answer

append date to osql made backup with batch

thumbs up for this forum and am glad there's so many volunteers around on line. I'm not familiar with batch, so maybe someone would be so kind to enlighten me with answer. Be very thankfull. I try to backup many sql db with osql and then rename them…
0
votes
1 answer

Is there a way to make NAnt catch exceptions and run a roll back script?

I am using NAnt to run some scrips for a deployment. It has simplified the process a lot. The issue now is that when there is an error I want the NAnt task to run my roll back scripts. However I only know of the option to fail on error for my tasks.…
QueueHammer
  • 9,487
  • 12
  • 61
  • 89
0
votes
1 answer

adding .bat confirmation for user entering variables

Hi I have been editing my script with some forum help. I just need to add one last section. I need to indicate to the user running the .BAT file if the row was inserted or not? can anyone help me polish this off and I can go home a happy man ! @echo…
Chris Wood
  • 498
  • 9
  • 27