Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Output to log file - append option?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/09/2009 :  10:46:31  Show Profile  Reply with Quote
Hi there - anyone know how to append to a log file instead of the default overwrite? I've googled it but can’t find anything. I've tried sticking in a –a for append but it doesn’t like it.

:out $(root)\log\bla.log
:out –a $(root)\log\bla.log

Thanks in advance, Jon

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1834 Posts

Posted - 09/09/2009 :  18:33:32  Show Profile  Reply with Quote
Which log file are you referring to?

=======================================
Men build too many walls and not enough bridges. -Isaac Newton, philosopher and mathematician (1642-1727)
Go to Top of Page

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/10/2009 :  04:29:19  Show Profile  Reply with Quote
Hi - any file. This is just a txt file for logging purposes. I can't find any documentation on the "out" command so I don't know if there's an append option or not. This has got to be pretty straightforward! (I don't suppose t-sql supports interactive help dos does it?)

Cheers.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8781 Posts

Posted - 09/10/2009 :  04:38:48  Show Profile  Visit webfred's Homepage  Reply with Quote
My question is:
Which command or application do you use with ':out'?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/10/2009 :  04:40:09  Show Profile  Reply with Quote
Sorry, sqlcmd.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8781 Posts

Posted - 09/10/2009 :  04:50:37  Show Profile  Visit webfred's Homepage  Reply with Quote
Syntax isn't ':out' it is '-o' and it is not a log file it is a result file


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/10/2009 :  05:19:05  Show Profile  Reply with Quote
Ok, sorry I'm not being overly clear here. I wasn't referring outputting on the same line of the sqlcmd. Here's what i'm doing. Easy stuff...

I create a connection via sqlcmd and call a script:

sqlcmd -S %svr% -i "%root%\create\db\crt_database.sql" -v db=%db%

At the start of the crt_database.sql file, I have:

:out c:\mylog.log

Which works fine. Then I create a new connection and call a 2nd script file which contains the same logging command. I want to append the log of the 2nd script to c:\mylog.log. By default the 2nd log overwrites the 1st.

Sorry for the confusion...
Go to Top of Page

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/10/2009 :  05:49:55  Show Profile  Reply with Quote
ok, another way is to use your -o command, e.g.

sqlcmd -S %svr% -i "%root%\create\db\crt_database.sql" -v db=%db% -o c:\mylog.log

But how can you append to this file e.g.
sqlcmd -S %svr% -i "%root%\create\db\crt_database.sql" -v db=%db% -o c:\mylog.log
sqlcmd -S %svr% -i "%root%\create\db\doSomethingElse" -v db=%db% -o c:\mylog.log
sqlcmd -S %svr% -i "%root%\create\db\AnddoSomethingElse" -v db=%db% -o c:\mylog.log

in order to have logs for the 3 outputs in 1 file. By default, you'll only see the output for the last one 'AnddoSomethingElse'

Cheers.
Go to Top of Page

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/11/2009 :  06:01:34  Show Profile  Reply with Quote
Hmmm - still struggling. Ideas?
Go to Top of Page

YellowBug
Aged Yak Warrior

United Kingdom
616 Posts

Posted - 09/11/2009 :  06:48:35  Show Profile  Reply with Quote
I suggest the old-fashioned re-direction, with >>, like:

sqlcmd -S %svr% -i "%root%\create\db\crt_database.sql" -v db=%db% >> c:\mylog.log
sqlcmd -S %svr% -i "%root%\create\db\doSomethingElse" -v db=%db% >> c\:\mylog.log
sqlcmd -S %svr% -i "%root%\create\db\AnddoSomethingElse" -v db=%db% >> c:\mylog.log
Go to Top of Page

strauss_jon
Starting Member

United Kingdom
23 Posts

Posted - 09/11/2009 :  06:58:30  Show Profile  Reply with Quote
Brilliant, that's all I wanted! Thanks very much...Easy when you know how :-)
Go to Top of Page

YellowBug
Aged Yak Warrior

United Kingdom
616 Posts

Posted - 09/11/2009 :  07:12:09  Show Profile  Reply with Quote
You're welcome. Glad I could help!
Go to Top of Page

TonyTheDBA
Posting Yak Master

United Kingdom
121 Posts

Posted - 10/07/2013 :  08:30:23  Show Profile  Reply with Quote
Thanks again Yellowbug . . . I'll go back to good old fashioned redirection

--
Regards
Tony The DBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000