Showing posts with label executes. Show all posts
Showing posts with label executes. Show all posts

Tuesday, March 27, 2012

Getting a .sql to execute another .sql

I would like to create a "parent" .sql file that when executed goes off and executes the contents a number of other "children" .sql files
Would anybody know how to do this
What happens if one of the .sql files fails? Will the others keep on running
ThankDepending on what you are trying to do, you might be able to use Xp_cmdshell
with OSQL. See BOL for details on both
--
Ray Higdon MCSE, MCDBA, CCNA
--
"lk1" <anonymous@.discussions.microsoft.com> wrote in message
news:A2CBAB73-B4EC-4852-A6D9-5DCE970A7282@.microsoft.com...
> I would like to create a "parent" .sql file that when executed goes off
and executes the contents a number of other "children" .sql files.
> Would anybody know how to do this?
> What happens if one of the .sql files fails? Will the others keep on
running?
> Thanks
>

Getting a .sql to execute another .sql

I would like to create a "parent" .sql file that when executed goes off and
executes the contents a number of other "children" .sql files.
Would anybody know how to do this?
What happens if one of the .sql files fails? Will the others keep on runnin
g?
ThanksDepending on what you are trying to do, you might be able to use Xp_cmdshell
with OSQL. See BOL for details on both
Ray Higdon MCSE, MCDBA, CCNA
--
"lk1" <anonymous@.discussions.microsoft.com> wrote in message
news:A2CBAB73-B4EC-4852-A6D9-5DCE970A7282@.microsoft.com...
> I would like to create a "parent" .sql file that when executed goes off
and executes the contents a number of other "children" .sql files.
> Would anybody know how to do this?
> What happens if one of the .sql files fails? Will the others keep on
running?
> Thanks
>

Friday, March 9, 2012

Get the error in dos cmd line

Hi everyone,

I have a cmd file that executes sql statements:

something like this:

Code Snippet

OSQL -S %sqlServer% -E -b -n -i DATABASE.sql"
IF ERRORLEVEL 1 GOTO error
echo -

...

:error
@.ECHO An error occured in [%errorLevel%]
echo [%errorLevel%] > %1

GOTO EXIT


if there is an error, I print the errorlevel in a txt file wich is a parameter in the command (%1)

What I want is: instead of sending the %errorlevel% to the txt, I want to send the error description but I don't know the variable that keeps the error description.

Any help please

Thanx in advance

I really need to know if there is some variable that gives me the sql error because when I execute the cmd, if there's an error

the error is printed int the cmd window.

The errorlevel var just give me the number "1" but I would like to get something like

"An error in database ocurred due to database already exists" or something like that.

Please I'll apreciate any ideias you may have
|||

Instead of overwriting the error log file, I would just append the error to the file instead.

Code Snippet

ECHO OFF

OSQL -S %sqlServer% -E -b -n -i test.sql > %1
IF ERRORLEVEL 1 GOTO error
ECHO "" > %1
EXIT


:error
@.ECHO An error occured in [%errorLevel%]
echo [%errorLevel%] >> %1

This way you either have a blank file, or you have a file with an error message and errorLevel code.

|||Thanx for the answer ShawnNWF, that will do the trick for sure

Get the error in dos cmd line

Hi everyone,

I have a cmd file that executes sql statements:

something like this:

Code Snippet

OSQL -S %sqlServer% -E -b -n -i DATABASE.sql"
IF ERRORLEVEL 1 GOTO error
echo -

...

:error
@.ECHO An error occured in [%errorLevel%]
echo [%errorLevel%] > %1

GOTO EXIT


if there is an error, I print the errorlevel in a txt file wich is a parameter in the command (%1)

What I want is: instead of sending the %errorlevel% to the txt, I want to send the error description but I don't know the variable that keeps the error description.

Any help please

Thanx in advance

I really need to know if there is some variable that gives me the sql error because when I execute the cmd, if there's an error

the error is printed int the cmd window.

The errorlevel var just give me the number "1" but I would like to get something like

"An error in database ocurred due to database already exists" or something like that.

Please I'll apreciate any ideias you may have
|||

Instead of overwriting the error log file, I would just append the error to the file instead.

Code Snippet

ECHO OFF

OSQL -S %sqlServer% -E -b -n -i test.sql > %1
IF ERRORLEVEL 1 GOTO error
ECHO "" > %1
EXIT


:error
@.ECHO An error occured in [%errorLevel%]
echo [%errorLevel%] >> %1

This way you either have a blank file, or you have a file with an error message and errorLevel code.

|||Thanx for the answer ShawnNWF, that will do the trick for sure