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
 Old Forums
 CLOSED - General SQL Server
 Create file

Author  Topic 

TAS
Yak Posting Veteran

65 Posts

Posted - 2004-08-24 : 14:10:16
I want to use master..xpcmd_shell to create file,but it doesn't work.

exec master..xp_cmdshell 'echo open > C:\some.txt'

It gives me output of NULL and file is not created.

Anyone knows why?

X002548
Not Just a Number

15586 Posts

Posted - 2004-08-24 : 14:15:20
I do something like....


Select @Log_Id = IsNull(Max(IsNull(Log_Id,0)),0) + 1 From Tax_Load_Log

SET @var = RTrim(Convert(Char(20),@Log_Id)) + '|U|'+RTrim(Convert(char(50),GetDate(),109))+'|Starting Quarterly Load Process'
SET @cmd = 'echo ' + '"|' + @var + '|"' + ' > d:\Data\Tax\log_out.txt'
SET @Command_string = 'EXEC master..xp_cmdshell ''' + @cmd + ''', NO_OUTPUT'

Exec(@Command_String)


Make sure to use >> to append lines to the file

I then load this pipe delimeted file to the log table on the way out of the sprocs....



Brett

8-)
Go to Top of Page

TAS
Yak Posting Veteran

65 Posts

Posted - 2004-08-24 : 14:29:40
Thank you,but still doesn't work.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-08-24 : 16:45:58
Well you need to declare the variables...and create a log table...

This runs every quarter now for years...

I do the exact same thing for every other batch process that I write...



Brett

8-)
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-08-24 : 16:51:55
exec master..xp_cmdshell 'echo open > C:\some.txt'

should work unles there's a permissions problem which is unlikely.

The file will be created on the server not your workstation which is about the only thing I can think of.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -