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

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 copy message to log file

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-07-03 : 07:26:57
I used a store procedure mySp to insert records into a table. After runing "exec mysp" in SQL query analyzer, a short message displays "xxx rows effected". Now, I want to use a batch file to run mysp and copy "xxx rows effected" message to a log file. How to code it? Can I use:

exec mysp >> c:\mylog.txt ???

Kristen
Test

22859 Posts

Posted - 2005-07-03 : 08:47:20
You can use OSQL.EXE, from DOS, to run scripts etc. There is an option to save the outputs / errors / etc. to a file.

Kristen
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-07-03 : 10:35:04
Thank you for help. I tried it and works. But, output all detail. What I need is last line:
"(23 rows affected)". Is it possible?
Here is my batch file:
osql -E -d pubs -S MYSERVER -Q "select * from authors" -o c:\osql.txt
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-07-03 : 10:43:09
I think that I can do it like:
osql -E -d pubs -S MYSERVER -Q "select count(*) from authors" -o c:\osql.txt
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-07-04 : 06:42:35
"I think that I can do it like:
osql -E -d pubs -S MYSERVER -Q "select count(*) from authors" -o c:\osql.txt"

In doing this...you are executing a 2nd query...and there may be a time-interval and no guarantee that the answer you get will correlate with what you wanted out of the original query.

Best approach would be to filter the error/output file from the 1st query and parse/determine the information you require.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-07-04 : 09:35:49
Perhaps:

osql -E -d pubs -S MYSERVER -Q "select * from authors; SELECT [RowCount] = @@ROWCOUNT" -o c:\osql.txt

Kristen
Go to Top of Page
   

- Advertisement -