steve your example would just return the results from the cmd prompt; I think the original poster wanted to capture the results of his dbcc command in both a table and in the output file.
what's wierd for me is this command:
dbcc checkdb (SandBox) with no_infomsgs does not return any results....so why bother capturing the results in a text file in the first place? maybe it only returns results if there was a problem/failure? {edit} dbcc only returns messages, so no_infomsgs will never return results at all...so there's no need to capture it in both a table and a file...it would be better to not include that i think.{/edit}
anyway
this complete command returns this for results:
cmdoutid
NULL1
the code:
declare
@cmd varchar(1000),
@FileNameOut varchar(200),
@user varchar(30),
@pass varchar(30) ,
@db varchar(30)
SET @user='sa'
SET @pass='NotARealPassword'
SET @db ='SandBox'
set @FileNameOut ='OutputConsistencia_'+ @db
select @cmd = 'osql -U' + @user + ' -P' + @pass + ' -S -Q"dbcc checkdb (''' + @db + ''') with no_infomsgs" -o"c:\' + @FileNameOut + '.txt" -w500'
create table #t (cmdout nvarchar(255), id int identity)
Insert #t Exec master..xp_cmdshell @cmd
Select * from #t
Lowell