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 2008 Forums
 SQL Server Administration (2008)
 osql and sqlcmd not giving much output

Author  Topic 

Adrenaline Seed
Starting Member

10 Posts

Posted - 2011-02-10 : 17:05:15
Anyone know why sometimes osql just says ">1" and sqlcmd just outputs nothing and when I run the same select statement in Studio I get all the information I am looking for.

Here is the select statement I am using and the commands I am using:

SELECT command,
s.text,
start_time,
percent_complete,
CAST(((DATEDIFF(s,start_time,GetDate()))/3600) as varchar) + ' hour(s), '
+ CAST((DATEDIFF(s,start_time,GetDate())%3600)/60 as varchar) + 'min, '
+ CAST((DATEDIFF(s,start_time,GetDate())%60) as varchar) + ' sec' as running_time,
CAST((estimated_completion_time/3600000) as varchar) + ' hour(s), '
+ CAST((estimated_completion_time %3600000)/60000 as varchar) + 'min, '
+ CAST((estimated_completion_time %60000)/1000 as varchar) + ' sec' as est_time_to_go,
dateadd(second,estimated_completion_time/1000, getdate()) as est_completion_time
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) s
WHERE r.command in ('RESTORE DATABASE', 'BACKUP DATABASE', 'RESTORE LOG', 'BACKUP LOG')



>osql -E -Sneosql -dmaster -i\\dwsql2005\c$\hta\sql\GetTimeEstimate.sql
-o c:\timeestimate.log

>sqlcmd -E -Sneosql -dmaster -i\\dwsql2005\c$\hta\sql\GetTimeEstimate.sql
-o c:\timeestimate.log

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-10 : 17:25:11
Because you are outputting the data to a file, so it will not go to the screen. Or am I missing your question completely?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Adrenaline Seed
Starting Member

10 Posts

Posted - 2011-02-10 : 17:35:24
I did not want it to go to the screen. There is a difference from printing to the screen and printing to a file?

I print all my output to files and it normally works correctly.
Go to Top of Page

Adrenaline Seed
Starting Member

10 Posts

Posted - 2011-02-10 : 17:38:13
I just tried printing to the screen, by removing the -o, I get the same result.
Go to Top of Page

Adrenaline Seed
Starting Member

10 Posts

Posted - 2011-02-10 : 17:42:11
Ah it started working now, must have had a problem accessing the .sql file or something which was causing it to just output ">1"
Go to Top of Page
   

- Advertisement -