set up sql command

Help with setting up and configuring custom user tools in UltraEdit (based on command line input)

set up sql command

Postby jcpw » Mon Aug 07, 2006 2:56 pm

I want to set up a tool using osql (the command line version of sql server's tsql) to run queries. Here is my command:

"c:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe" -E -S servername -d dbname -Q "%sel" -w 1000

Of course, "servername" and "dbname" are replaced appropriately.

If I run this command in a DOS window (I'm running Win2k) and replace "%sel" with my sql query (which is simply "select count(*) from tableinfo"), it runs fine and I get back the result, which is the number 16 (there are 16 records).

However, I haven't been able to get the result to appear in UE's output window. At most, when I highlight the query and run the tool, I get a messagebox that says "Operation completed successfully". That's fine, but I really want to see the result. Also, it wants to save the query in a text file, which I don't need. I just want to see the result.

I have tried various combinations of option settings, with no luck (although with some settings it does put the command in the output window!) then I thought I'd see if someone in the forums can help me.

Just for the record, besides the command as above, my tool settings are:
Options - DOS Program; save active file; save all files first
Output - Append to existing;Capture output;No replace
User avatar
jcpw
Newbie
 
Posts: 1
Joined: Sun Aug 06, 2006 11:00 pm

Re: set up sql command

Postby Mofi » Tue Aug 08, 2006 5:22 am

I don't have installed Microsoft's SQL server. But according to the doc about the osql Utility, I think the parameter -r 1 could help.

You should also try it with Show DOS Box enabled for the user tool in UltraEdit. And test it also with Alternate Capture Method in menu Advanced enabled/disabled.

If the suggestions above do not help, run osql with a batch file like this one:

@echo off
"c:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe" -E -S servername -d dbname -Q "%1" -w 1000 -o "%temp%\osql_output.tmp"
if exist "%temp%\osql_output.tmp" type "%temp%\osql_output.tmp"
if exist "%temp%\osql_output.tmp" del "%temp%\osql_output.tmp" >nul


In the user tool configuration of UltraEdit you have to specify only the batch file and the parameter "%sel".
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: set up sql command

Postby ch_tx » Wed Aug 09, 2006 1:57 pm

This works for me using UE 12.10a. I am sending the output to a new window, but selecting "Output to List Box" works as well.

"C:\...\osql.exe" -S server -d database -E -w 8092 -Q"%sel%"

Replace "..." in path with your path to osql.exe.

Options tab:
DOS Program selected, nothing else checked.

Output tab:
Append to existing selected, Capture Output checked, and No Replace selected.
User avatar
ch_tx
Newbie
 
Posts: 2
Joined: Sun Aug 06, 2006 11:00 pm


Return to Custom User Tools/Tool Configuration