Home All Groups Group Topic Archive Search About

trying unsuccessfully to produce OSQL error

Author
7 Sep 2006 3:01 PM
Rick Charnes
I have a .CMD file with an OSQL command that does a simple -Q "DELETE
FROM MYTABLE".  Under some circumstances this table does not exist, and
I'd like to know about in the batch file.  I'm trying to trap for this
with:

if errorlevel 1 goto :errorlabel

But OSQL doesn't seem to set the DOS errorlevel if the query fails.  Any
thoughts?

Author
7 Sep 2006 3:37 PM
Narayana Vyas Kondreddi
Are you using the  -b parameter of osql?
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/


Show quote
"Rick Charnes" <rickxyz--nospam.zyxcharnes@thehartford.com> wrote in message
news:MPG.1f69fe43a7c0a02798994c@msnews.microsoft.com...
>I have a .CMD file with an OSQL command that does a simple -Q "DELETE
> FROM MYTABLE".  Under some circumstances this table does not exist, and
> I'd like to know about in the batch file.  I'm trying to trap for this
> with:
>
> if errorlevel 1 goto :errorlabel
>
> But OSQL doesn't seem to set the DOS errorlevel if the query fails.  Any
> thoughts?
Author
7 Sep 2006 4:24 PM
Rick Charnes
THANK YOU!  I hadn't known about this parm.  Thanks much.

Btw, OSQLP Help for -b says: "The value returned to the DOS ERRORLEVEL
variable is 1 when the SQL Server error message has a severity of 10 or
greater..."

The SQL error message I get is:

Msg 208, Level 16, State 1,...

Just to confirm: does "Level 16" indicate the "severity"?


In article <elebTOp0GHA.4***@TK2MSFTNGP06.phx.gbl>,
answer***@hotmail.com says...
Show quote
> Are you using the  -b parameter of osql?
>
Author
7 Sep 2006 8:12 PM
Narayana Vyas Kondreddi
That's right.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/



"Rick Charnes" <rickxyz--nospam.zyxcharnes@thehartford.com> wrote in message
news:MPG.1f6a11b4eac83f5598994d@msnews.microsoft.com...
> THANK YOU!  I hadn't known about this parm.  Thanks much.
>
> Btw, OSQLP Help for -b says: "The value returned to the DOS ERRORLEVEL
> variable is 1 when the SQL Server error message has a severity of 10 or
> greater..."
>
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/



Show quote
> The SQL error message I get is:
>
> Msg 208, Level 16, State 1,...
>
> Just to confirm: does "Level 16" indicate the "severity"?
>
>
> In article <elebTOp0GHA.4***@TK2MSFTNGP06.phx.gbl>,
> answer***@hotmail.com says...
>> Are you using the  -b parameter of osql?
>>

AddThis Social Bookmark Button