Re: Sql Query

From: Ray at <%=sLocation%> [MVP] (%=sLocation%)
Date: 08/20/04


Date: Fri, 20 Aug 2004 11:24:55 -0400

osql won't connect to an AS/400, only SQL Server, AFAIK. Are you familiar
with VB Script at all? You could ~~try~~ something like this after
registering cscript to be the default script host. (cscript.exe
//H:CScript)

csql.vbs:

If WScript.Arguments.Count > 0 Then Call ReturnRS(WScript.Arguments(0))

''connection string from www.connectionstrings.com
Const CONNECTION_STRING = "Provider=DB2OLEDB;Network Transport
Library=TCPIP;Network Address=XXX.XXX.XXX.XXX;Initial Catalog=MyCtlg;Package
Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW"
Function ReturnRS(sql)
 Dim oADO, oRS
 Set oADO = CreateObject("ADODB.Connection")
 oADO.Open CONNECTION_STRING
 Set oRS = oADO.Execute(sql)
 If Not oRS.EOF Then ReturnRS = oRS.GetString(2,,vbTab,vbCrLf)
 oADO.Close
 Set oADO = Nothing
End Function

And then call it with:

csql "select something from somwhere where something='something'"

This is probably far from ideal though! There's probably a command prompt
"osql" for DB/2 out there somewhere already...

Ray at work

"Barney" <anonymous@discussions.microsoft.com> wrote in message
news:9c9601c486ad$bbb03cd0$a401280a@phx.gbl...
> We dont have an SQL server - we have an AS400 running
> DB2. Where can I download osql.exe?
>>-----Original Message-----
>>Use osql.exe in your batch, which you should have from
> any SQL Server
>>installation, including the "client tools only" install.
>>
>>osql -?
>>
>>usage: osql [-U login id] [-P
> password]
>> [-S server] [-H hostname] [-E
> trusted connection]
>> [-d use database name] [-l login timeout] [-t
> query timeout]
>> [-h headers] [-s colseparator] [-w
> columnwidth]
>> [-a packetsize] [-e echo input] [-I
> Enable Quoted
>>Identifiers]
>> [-L list servers] [-c cmdend] [-D ODBC
> DSN name]
>> [-q "cmdline query"] [-Q "cmdline query" and exit]
>> [-n remove numbering] [-m errorlevel]
>> [-r msgs to stderr] [-V severitylevel]
>> [-i inputfile] [-o outputfile]
>> [-p print statistics] [-b On error batch abort]
>> [-O use Old ISQL behavior disables the following]
>> <EOF> batch processing
>> Auto console width scaling
>> Wide messages
>> default errorlevel is -1 vs 1
>> [-? show syntax summary]
>>
>>Ray at work
>>
>>"Patrick Bonneau" <anonymous@discussions.microsoft.com>
> wrote in message
>>news:84b001c48525$712aefe0$a401280a@phx.gbl...
>>> Is there away to make a sql query with a batch file?
>>>
>>> If so, what is the utility for doing this?
>>>
>>
>>
>>.
>>



Relevant Pages

  • Re: osql using :r and GO
    ... Kalen Delaney ... SQL Server MVP ... >> Normally, GO is caught by osql itself, and never makes it to the back ... Instead of having a script with:r, ...
    (microsoft.public.sqlserver.programming)
  • Re: osql using :r and GO
    ... > sends it directly to SQL Server for parsing, and the SQL Server doesn't like ... > Normally, GO is caught by osql itself, and never makes it to the back end. ... Instead of having a script with:r, ... > call xp_cmdshell which would call osql with the embedded script as a ...
    (microsoft.public.sqlserver.programming)
  • Re: Running Simultaneous Queries
    ... You could have a .CMD file that uses multiple invocations of: ... START CMD /C osql ... ... you could run a VB script that does much the same thing. ... Columnist, SQL Server Professional ...
    (microsoft.public.sqlserver.server)
  • Re: osql using :r and GO
    ... As you have noticed, the GO cannot be included in the:r script, because the ... sends it directly to SQL Server for parsing, and the SQL Server doesn't like ... Normally, GO is caught by osql itself, and never makes it to the back end. ... > CREATE TRIGGER A1_RBUI ...
    (microsoft.public.sqlserver.programming)
  • Re: Error 15401 using sp_grantlogin (not addressed by current KB articles)
    ... Restarting Windows 2000 resolved the problem for this particular account, ... confused when it sees a duplicate SID. ... > One way to get SQL Server to agree with the renamed NT ... > Preview (to ensure the script was created), ...
    (microsoft.public.sqlserver.security)